Agnai API setup: base URL, key, and the format field
Updated 2026-07-15
In Agnai, open a preset's AI settings, set the service to Third Party, and fill four fields: an OpenAI-compatible base URL, your API key, a Format setting matched to that API's shape, and the exact model ID. Agnai does not infer any of these for you, so a URL with a stray path or a Format built for a different API's response shape produces empty or garbled replies with no clear error message.
Quick answer: the fields Agnai's Third Party service needs
Agnai's Third Party connection lives inside a preset, not as one global setting. Open Settings, go to Presets (some builds label this AI Settings), create a new preset or edit an existing one, and set Service to Third Party. Four fields decide whether the connection works: Base URL, an OpenAI-compatible endpoint that should stop at /v1, for example https://api.apisrouter.com/v1; API Key, your provider's secret key; Format, which tells Agnai how to shape the outgoing request, set to OpenAI so it builds a Chat Completions payload instead of a raw text prompt; and Model, the exact ID your key can call, such as deepseek-v4-flash. Saving the preset is not the last step. Agnai applies presets per chat or per character, so an older Kobold or native-service preset left active on a chat keeps routing there even after you build a working Third Party preset elsewhere. Assign the new preset explicitly, either as your default or on the specific chat, before assuming the connection is broken.
What each Third Party field is actually doing
Two things ride along on every message regardless of whether those four fields are correct: the character definition and persona you built, and any memory book entries currently active for the scene. Agnai resends both, plus recent chat history, on every turn, the same way JanitorAI resends a character card and SillyTavern resends its prompt template. None of that lives in the Third Party fields, but it is what actually drives the size, and therefore the cost, of every request those fields make possible.
- Base URL: the address Agnai sends every request to. It should stop at /v1 for most OpenAI-compatible providers; Agnai appends the completions path itself, so a URL that already ends in /chat/completions produces a doubled, broken path.
- API key: sent as an Authorization header to the base URL only. Depending on your Agnai version it sits directly in the preset or under a separate registered-keys section in Settings; either way it never appears in the chat itself.
- Format: controls the shape of the outgoing request and how Agnai parses the reply. OpenAI-compatible providers expect the Chat Completions shape, a messages array with roles. Picking a Format built for a different API's response schema is a common cause of a connection that accepts the key but returns garbled or empty text.
- Model: sent as the model parameter on every request. It has to match a real ID from your provider's catalog, not a display name; a mistyped or outdated ID usually surfaces as a model-not-found style error rather than silence.
Which model to point Agnai at, and why
The base URL, key, and Format stay identical across every model you try; only the Model field changes, so the practical move is one saved preset per model you actually use, the same pattern JanitorAI and SillyTavern users settle into. Discussion around Agnai's Third Party option leans toward the same handful of budget models favored on other companion frontends, for the same reason: steady character-card adherence at a low per-token rate matters more in a long-running chat than a benchmark score. DeepSeek V4 Flash is the common starting point for value, with Pro a step up for chats that lean on a big memory book or a group scene. GLM-5 and Kimi K2.6 are solid budget picks with a different prose feel worth rotating in when a chat starts to feel samey. Grok is notable because xAI's published policy explicitly allows mature themes in fiction, which some users weigh for darker storylines. Claude writes the strongest prose on this list, but Anthropic's usage policy prohibits explicit content, so treat it as a SFW option for character voice and description rather than anything else.
| Model ID | Fit for Agnai chats | Content policy notes |
|---|---|---|
| deepseek-v4-flash | Default pick; best value for long chats | Flexible policy for fictional content |
| deepseek-v4-pro | Steadier recall for big memory books and group chats | Same family, higher rate |
| glm-5 | Distinct prose voice on a budget | Accommodates fiction |
| kimi-k2.6 | Different prose feel worth rotating in | Accommodates fiction |
| grok-4.5 | Distinct voice; 500K context window | xAI policy permits mature fictional themes |
| claude-sonnet-4-6 | Best prose quality per dollar | SFW creative writing only per Anthropic policy |
| claude-opus-4-7 | Deepest characterization | SFW creative writing only |
| gemini-3.5-flash | Fast, long-context all-rounder | Standard Google policy applies |
What a chat session actually costs
Agnai resends the character definition, persona, active memory book entries, and recent history with every message, so input tokens dominate the bill, the same shape as JanitorAI and SillyTavern. A modest setup with a couple of active memory book entries commonly runs around 4,000 input tokens and 300 output tokens per message. The table below prices that assumption across 1,000 messages, roughly a heavy month of daily chatting. A bigger memory book or a longer retained history pushes the input side up; a leaner one pulls it down. These are APIsRouter catalog rates, from an OpenAI-compatible gateway with pay-as-you-go billing and no subscription: global models are priced 20% below official list, Chinese models sit under their official rates, the first top-up adds a +100% balance bonus, and the /topup checkout skips the signup form, taking payment first and emailing the key.
| Model | Input $/1M | Output $/1M | Est. cost per 1,000 messages |
|---|---|---|---|
| deepseek-v4-flash | $0.126 | $0.252 | ~$0.58 |
| deepseek-v4-pro | $0.3915 | $0.783 | ~$1.80 |
| glm-5 | $0.514 | $2.314 | ~$2.75 |
| kimi-k2.6 | $0.855 | $3.60 | ~$4.50 |
| gemini-3.5-flash | $1.20 | $7.20 | ~$6.96 |
| grok-4.5 | $1.60 | $4.80 | ~$7.84 |
| claude-sonnet-4-6 | $2.40 | $12.00 | ~$13.20 |
| claude-opus-4-7 | $4.00 | $20.00 | ~$22.00 |
Why the connection breaks, or the bill jumps, without warning
Test the four fields in isolation before assuming any one of them is the culprit. The curl example later on this page is the fastest way to separate a bad URL or key from a Format problem inside Agnai itself.
- Base URL ending in /chat/completions instead of /v1: Agnai appends the path itself, so the request lands on a doubled URL and fails before it reaches your provider.
- Format mismatched to the endpoint: the connection accepts the key but sends or parses the wrong shape, which reads as a garbled or empty reply rather than an obvious error.
- A mistyped or renamed Model ID: usually surfaces as a model-not-found response, not silence, so it is worth checking first when nothing comes back at all.
- A working preset saved but never assigned: the chat keeps using whichever service was active before, so the new Third Party preset looks broken when it was simply never applied.
- Memory book entries left active from a finished arc: they keep riding on every message, quietly inflating input tokens on scenes that no longer need them.
- Free, queue-based community compute mistaken for a broken key: a full queue on shared backends looks identical to an authentication failure from the chat window, and the fix is unrelated to your Third Party fields.
Third Party key versus Agnai's other connection options
Agnai reaches models three broad ways, and Third Party is only one of them. Shared community compute needs no key at all, but capacity is queued and shared, so response time and availability move with demand rather than with anything you control. A native integration talks to one specific provider directly and is as reliable as that provider, but it locks you to whatever models that integration supports. Third Party is the general-purpose option: any OpenAI-compatible endpoint works once you have a key, at the cost of the one-time setup covered above.
| Option | Setup required | Reliability | Model choice |
|---|---|---|---|
| Shared community compute | None; works without a key | Queued, capacity varies with demand | Limited to whatever the pool runs |
| Native provider integration | One provider-specific API key | As reliable as that one provider | Locked to that provider's models |
| Third Party (OpenAI-compatible) | Base URL, key, Format, and Model | As reliable as the endpoint you pick | Any model your key is allowed to call |
Fixing it: verify outside Agnai, then match the fields
The curl call below is exactly what Agnai's Third Party connection does under the hood: same URL, same header, same JSON shape. If it returns a completion, your Base URL, key, and Model are all valid, and a broken connection inside Agnai points at the Format field or an unassigned preset instead. The second call lists every model ID your key can use, which settles any doubt about spelling before you touch the Model field again.
- Test the endpoint directly with curl before touching Agnai again, so you know whether the URL, key, or model ID is at fault before blaming the app.
- Set Format to OpenAI whenever the provider is OpenAI-compatible. A Format built for a different API is the most common cause of a connection that accepts the key but returns junk.
- Paste the model ID exactly as the provider lists it, lowercase and unabbreviated, and recheck it against the provider's model list rather than a display name.
- Assign the working preset to the chat, or set it as your default, instead of leaving an older service active on that character.
- Prune memory book entries you are not using in the current scene; every active entry rides on every message whether the scene needs it or not.
- Point the same Third Party key at a lower-priced OpenAI-compatible endpoint for everyday chatting, and save a pricier flagship model for the scenes you actually care about.
curl https://api.apisrouter.com/v1/chat/completions \
-H "Authorization: Bearer sk-YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4-flash",
"messages": [{"role": "user", "content": "Say ready."}],
"max_tokens": 20
}'FAQ
What service do I pick in Agnai to use a custom API key?
Third Party. It is the general-purpose option for any OpenAI-compatible provider, distinct from the native integrations Agnai offers for a couple of specific services. Set Format to OpenAI so requests use the Chat Completions shape, then fill in the base URL, key, and model ID.
Why is my Agnai reply empty or garbled after connecting?
Almost always the Format field. It has to match the shape of the API you pointed at; a Format built for a different provider's response schema will connect and accept the key while still returning broken or empty text. Confirm the base URL stops at /v1 and the key has no trailing whitespace, then recheck Format before anything else.
Which model works best for roleplay in Agnai?
DeepSeek V4 Flash is the common starting point for value and long chats, with Pro a step up for complex memory books or group scenes. GLM-5 and Kimi K2.6 are solid budget picks. Claude writes the strongest prose but is SFW-only under Anthropic policy, and Grok suits mature fictional themes under xAI's published policy.
Does Agnai's memory book affect my API bill?
Yes. Every active memory book entry is resent as input tokens with the character definition and recent history on every message, the same mechanic as a SillyTavern lorebook or a detailed JanitorAI character card. Prune entries you no longer need for the current scene rather than leaving old arcs active.
What is the cheapest way to get a Third Party API key for Agnai?
APIsRouter is an OpenAI-compatible gateway with pay-as-you-go billing and no subscription: pay at /topup with no signup form, the key arrives by email, and the first top-up adds a +100% balance bonus. Budget models like deepseek-v4-flash then cost a fraction of a cent per message, which turns a small top-up into months of casual chatting.
Is Agnai free to use?
Agnai itself is free, open-source software, and its shared community compute option needs no key at all, though capacity is queued and varies with demand. A Third Party key bills per token on top of that, with budget models running a fraction of a cent per message for typical chat lengths.