Which API key do you need for AI roleplay, and how to get it
The short answer
- An API key is a password for a model provider's service. The app sends your chat to the provider with the key attached, and the provider bills your account there. The app itself charges nothing and sees nothing.
- A ChatGPT, Gemini, or Grok subscription is not an API key. API access is a separate account with its own prepaid balance, even at the same company.
- Start with OpenRouter if you want one key for every model, DeepSeek if you want the cheapest good roleplay model, and Google's free tier if you want to pay nothing and accept that Google reads the chats.
Pick a provider
- OpenRouter: one key, hundreds of models, prepaid credits. Models whose name ends in
:freecost nothing, capped at 20 requests a minute and 50 a day until you have bought $10 of credits in total, then 1,000 a day. Your account settings choose whether free-model traffic may go to providers that train on it. - DeepSeek: the model most roleplayers on a budget use, bought directly. Prepaid balance. DeepSeek Flash costs $0.30 per million input tokens and $1.20 per million output tokens at peak, half that off-peak, and far less when the context is a cache hit. Its privacy policy says your data is stored in the People's Republic of China.
- Google Gemini: a free tier with daily request caps per model, and a paid tier. On the free tier, Google's terms say the content you submit is used "to provide, improve, and develop Google products" and that human reviewers may read it. Paid usage is not used that way.
- OpenAI: prepaid credits, priced per million tokens. Data sent to the API "is not used to train or improve OpenAI models" unless you opt in, and abuse-monitoring logs are kept for up to 30 days. Its usage policies apply to what you write.
- xAI (Grok): prepaid credits from the developer console. Grok 4.6 is listed at $2 per million input tokens and $6 per million output tokens.
- Moonshot (Kimi): prepaid, priced per million tokens, with cache discounts. The K2 and K3 models are the ones to try.
Every one of these speaks the same OpenAI-style API, which is why one app can use any of them. Prices are the providers' own, read on September 16, 2026, and they change; the links at the bottom go to the live pages.
Get the key
The steps are the same everywhere: sign in, open the API keys page, create a key, copy it once. Most providers show the full key only at creation; if you lose it, make another.
- OpenRouter: openrouter.ai, sign in, Keys, Create key. Name it after the app you will use it in. You can set a spending cap on the key itself. Add credits under Credits, or use a
:freemodel first. - DeepSeek: platform.deepseek.com, API keys, Create new API key. Top up under Billing before the first message; there is no free allowance.
- Google Gemini: aistudio.google.com, Get API key. The free tier needs no card. Paid tiers start when you attach a billing account.
- OpenAI: platform.openai.com, API keys, Create new secret key. Add prepaid credits under Billing first.
- xAI: console.x.ai, create an API key, then purchase credits.
- Moonshot: platform.moonshot.ai, API keys, then recharge.
Put it in the app
In LonelyTavern: Settings, Providers, New provider. Pick the preset for your provider and it fills in the name, the base URL, and a sensible default model. Paste the key, tap Save provider, then Use. Other bring-your-own-key apps ask for the same three things:
- Base URL: the provider's API address, for example
https://openrouter.ai/api/v1orhttps://api.deepseek.com/v1. - Model: the exact model name from the provider's list. A typo here is the most common "it doesn't work".
- API key: the string you just copied. LonelyTavern stores it in the phone's keychain, never in the app database, and leaves it out of backups.
What a message costs
Providers bill per token, roughly three quarters of a word. A roleplay turn sends the whole recent conversation plus your character's card every time, so the input side dominates. A worked example on DeepSeek Flash at peak prices, with an 8,000-token conversation and a 300-token reply:
- Input: 8,000 tokens at $0.30 per million is $0.0024.
- Output: 300 tokens at $1.20 per million is $0.00036.
- Per message: about $0.003, so 100 messages a day is under $0.30. Cache hits on the unchanged part of the conversation cut the input price to $0.006 per million, which is why real bills come in lower.
Two habits keep bills predictable: cap the context size in the app so old messages are trimmed or summarized instead of resent, and set a per-key spending limit where the provider offers one.
Keep the key safe
- It is a password. Anyone with the key can spend your balance. Never paste it in a chat, a screenshot, or a public post.
- One key per app. Then a leak costs you one key, and the usage page tells you which app spent what.
- Leaked? Delete it and make a new one. OpenRouter scans public code for exposed keys and emails you; the other providers expect you to notice.
- Prepaid beats a card on file. A prepaid balance cannot run away from you.
Where the key goes on a phone
LonelyTavern is a bring-your-own-key character chat app for iPhone and Android. Presets for the six providers above, any other OpenAI-compatible endpoint by URL, the key in the keychain, and the characters and chats on the device. Free, no account, no ads, 18+.
Related guides: SillyTavern on iPhone · SillyTavern on Termux (Android) · all guides.
Sources
- OpenRouter: API rate limits: free-model caps and per-key credit limits
- OpenRouter: provider logging and data retention: the paid and free training settings
- OpenRouter: API authentication: creating keys, exposed-key notices
- DeepSeek: models and pricing: DeepSeek Flash peak, off-peak, and cache-hit prices
- DeepSeek: privacy policy: storage in the People's Republic of China
- Gemini API: pricing and terms: free tier, "Unpaid Services" data use, human review
- Gemini API: rate limits: tiers and daily caps
- OpenAI: your data: no training on API data by default, 30-day abuse logs
- xAI: developer docs: key creation, credits, Grok 4.6 prices
- Moonshot: model pricing: per-token billing and cache discounts
OpenRouter, DeepSeek, Google, OpenAI, xAI, and Moonshot are independent companies. LonelyTavern is not affiliated with or endorsed by any of them and earns nothing from your provider spending. Prices and policies were read on September 16, 2026 and may have changed since.
