AI companion app API:
chat, a voice and pictures on one key
Build an AI companion app on one prepaid key: streaming chat with mainstream or uncensored models, a voice for each reply, pictures and per-key limits.
Last updated 2026-11-05
Black Friday deposit bonus
Every qualifying top-up earns free credit, on top of any other offer.
Ends November 30
An AI companion app is a character people come back to: someone who remembers the conversation, answers in a voice of their own and sends a picture now and then. The pieces are three APIs, and on Lovely Router they share one key and one prepaid balance. Chat through the OpenAI or Anthropic API, streamed token by token, with any chat model: Claude, GPT and Gemini, or one of the uncensored models that stay in character without refusing. A voice from text to speech, designed once and saved. Pictures from the image generation API, drawn from the character's reference portrait so they look like the same person every time. Your backend holds the key, the memory and your users' accounts; per-key limits keep each part of your app inside its budget.
Hand it to your AI agent
Copy this prompt into Claude Code, Cursor, Codex or any coding agent. It tells the agent where the docs are and how to use your API key.
Build the backend of an AI companion app with streaming chat, a speech voice and pictures on one Lovely Router key. - Docs (read first): https://lovelyrouter.com/docs/models/hosted.md and https://lovelyrouter.com/docs/api/audio.md and https://lovelyrouter.com/docs/models/images.md - Chat: POST https://lovelyrouter.com/v1/chat/completions with `stream: true` (pick the model from GET https://lovelyrouter.com/v1/models). Voice: POST https://lovelyrouter.com/v1/audio/speech. Pictures: POST https://lovelyrouter.com/v1/images/generations. Keep each end user's quota in this backend. - Auth: read my API key from the LOVELY_API_KEY environment variable and send it as `Authorization: Bearer $LOVELY_API_KEY`. Never print or commit the key. If it is not set, ask me to create one at https://lovelyrouter.com/app/keys. - Billing is prepaid: every call is charged to my balance, so test with a small request before running anything large. - Every docs page is plain Markdown; the full index is https://lovelyrouter.com/llms.txt. My task: <the companion's persona, its voice and the app stack>
How it works
Write the character
A system prompt with who the companion is: name, personality, how they talk, what they remember about the user. Your backend keeps the conversation and sends the recent turns, plus a short summary of older ones, with every request.
Stream the replies
Send the conversation to
POST /v1/chat/completions(or/v1/messages) withstream: true, and show the words as they arrive. Change the model per request: a fast, inexpensive one for small talk, a stronger one for long scenes.Give them a voice
Design the companion's voice once with
qwen3-ttsfrom a description, save it withPOST /v1/audio/voices, and speak each reply with its id. The audio comes back when the whole reply is spoken, as MP3 or Opus.Send a picture
Keep one reference portrait of the character. When the story calls for a picture, send it to
POST /v1/images/editswith a prompt for the scene, and the image keeps the same face and look.
A reply, its voice and a picture
Stream the reply in Node.js with the OpenAI SDK:
import OpenAI from 'openai';
const client = new OpenAI({ baseURL: 'https://lovelyrouter.com/v1', apiKey: process.env.LOVELY_API_KEY });
const stream = await client.chat.completions.create({
model: 'qwen3.5-9b-defiant-fable',
stream: true,
messages: [
{ role: 'system', content: 'You are Ava, a witty, warm companion. You remember that the user is training for a marathon. Keep replies short and talk like a friend.' },
...history, // the recent turns your backend keeps
{ role: 'user', content: 'Long run today. 28 km. My legs are gone.' },
],
});
let reply = '';
for await (const chunk of stream) {
const text = chunk.choices[0]?.delta?.content ?? '';
reply += text;
sendToClient(text); // forward each piece to the app as it arrives
}Then speak it in the companion's saved voice, and draw a picture from her reference portrait:
import base64
import os
from openai import OpenAI
client = OpenAI(base_url="https://lovelyrouter.com/v1", api_key=os.environ["LOVELY_API_KEY"])
with client.audio.speech.with_streaming_response.create(
model="qwen3-tts",
voice="voice_8f2c4a1e9b7d3f60a5c2e1d4", # Ava's saved voice
input=reply,
instructions="Warm and teasing, a little proud of them",
response_format="opus",
) as audio:
audio.stream_to_file("reply.ogg")
picture = client.images.edit(
model="gpt-image-2",
image=[open("ava-portrait.png", "rb")],
prompt="The woman from the image at a sunny café terrace, raising a coffee cup to the camera, phone selfie",
size="1024x1536",
)
open("ava-cafe.png", "wb").write(base64.b64decode(picture.data[0].b64_json))The streaming guide covers what each API's stream looks like and what a cancelled stream costs.
The models
Any chat model on your key works as the companion's mind. For characters that need to stay in role through dark, romantic or mature scenes without breaking off, the uncensored models are on the same endpoints:
| Model | Input → output | Price |
|---|---|---|
| DeepSeek V4.1 Flash Abliterated deepseek-v4.1-flash-abliterated | text+image | $0.80 in · $2.00 out per 1M tokens |
| Qwen3.5 9B Defiant Fable (uncensored) qwen3.5-9b-defiant-fable | text+image | $0.90 in · $14.40 out per 1M tokens |
| Qwen3.8 27B Heretic (uncensored) qwen3.8-27b-heretic | text+image | $1.40 in · $21.90 out per 1M tokens |
| Huihui Qwen3.8 27B (abliterated) huihui-qwen3.8-27b-abliterated | text+image | $1.45 in · $20.60 out per 1M tokens |
Live prices in USD, the same the API charges.
deepseek-v4.1-flash-abliteratedis the cheapest per token, with a long context and no warm-up.
qwen3.5-9b-defiant-fableis small and fast, made for chat, creative writing and roleplay.
qwen3.8-27b-hereticand huihui-qwen3.8-27b-abliterated are stronger 27B models that also read images users send.
dongfangshuo-27b-v2is tuned for Chinese fiction and roleplay.
The 27B and 9B models run on our own GPUs and sleep after 2 minutes without use; the first request after a quiet spell waits 10 to 30 seconds while one wakes, then they answer at full speed. In a busy app they stay awake. See hosted models.
The tools for the job
OpenAI Chat Completions, Anthropic Messages and Gemini, each streamed in its own format. The gateway holds back early failures so a reply that fails before its first token is retried on another channel. See streaming.
qwen3-tts and zonos2 through OpenAI's speech API: nine and three preset voices, voices designed from a description, emotions on zonos2, 10 or 40+ languages. Replies up to 4,096 characters. See text to speech.
GPT Image 2 and 2.5 edits with up to 16 reference images, at $0.04 per image, usually 40 seconds to 2 minutes each. The fast hosted image models take a few seconds once warm but only generate, without reference images. See images.
Each key can have a lifetime spend limit, a requests-per-minute limit, a concurrency limit, a model allow-list and an expiry date. Use one key per app and environment, and a separate key for anything that runs unattended. See API keys.
Limits for your users
Keys are created in the dashboard, so they are for your app's parts, not for each end user. Give the chat, voice and picture workers their own keys with the limits that fit, and keep a capped key for trials and demos. A key that hits its limit is refused with 402 (spend) or 429 (rate or concurrency) in the format of the API you called, and refused requests aren't billed. Per-user quotas, such as messages a day or pictures a week, belong in your own backend, which counts usage before it calls the API. Never ship a key in the app itself: keep it on your server.
Adult companions
Adult conversations and images are allowed for adults (18+). If your app offers them, verifying your users' age is your responsibility, and the Acceptable Use Policy applies: nothing involving minors, ever, and no sexual images of real people without their consent.
What you pay
Chat is billed per token at each model's own price, shown live above and on pricing. Speech is $0.036 per minute of audio, billed by the second: a 15-second voice reply costs $0.009. Pictures are $0.04 each with the GPT Image models. Everything comes out of one prepaid balance, and every call is in your logs with its key and charge.
Frequently asked questions
Does the companion remember past conversations?+
The model remembers what you send it. Your backend stores the conversation and sends the recent turns, plus a summary of older ones, with each request. The hosted models take 128K tokens of context.
Can the voice stream while the text is still arriving?+
No. Speech isn't streamed: the audio comes back when the reply is spoken. Many apps show the text first and play the voice a moment later, or speak sentence by sentence as each one completes.
Will the character look the same in every picture?+
Send the same reference portrait with every edit and describe only the scene. The GPT Image models keep the face and look from it.
Can I use uncensored models for roleplay?+
Yes. They follow the system prompt and stay in character without refusing, and Lovely Router adds no content filter. You are responsible for what your app generates.
Is NSFW content allowed?+
For adults only. Verify your users' age if your app offers it; content involving minors is never allowed.
Can I give each of my users their own API key?+
Keys are made in the dashboard, so they suit your app's parts and environments. Track per-user usage in your backend and enforce quotas there.
Can an AI agent build the app?+
Yes. Copy the prompt on this page into Claude Code, Cursor or Codex: it reads the Markdown docs and wires the chat, speech and image calls with your key.
For long stories with branching choices, see interactive fiction; to start, sign up and try a character in the playground.