---
title: "Agnai integration"
description: "Settings for using Agnai with MiniRouter."
canonical_url: "https://minirouter.sh/docs/integrations/agnai"
markdown_url: "https://minirouter.sh/docs/integrations/agnai.md"
last_updated: "2026-09-26"
---

# Agnai

Chat with any MiniRouter model in Agnai.

[Get a key](https://minirouter.sh/key)

[Agnai](https://github.com/agnaistic/agnai) is a multi-user character chat app, hosted at agnai.chat or on your own machine. Its Third-Party preset runs on any chat model in the [catalog](https://minirouter.sh/models), or the curated [roleplay list](https://minirouter.sh/models/roleplay), from one balance. See [Roleplay](https://minirouter.sh/use/roleplay) for data handling and accountless keys.

> **Note:** Every turn re-sends the card, memory and history. Input is most of the bill, so compare input rates. See [Cost per message](https://minirouter.sh/guides/roleplay-cost-per-message).

## Quick start

### 1. Open Agnai

**Hosted**

Open [agnai.chat](https://agnai.chat).

**Self-hosted**

```sh
npm install agnai -g
agnai
```

Then open `http://localhost:3001`.

### 2. Create a key

[Create a key](https://minirouter.sh/key). Optionally test it before opening Agnai.

```sh
export MINIROUTER_KEY=mr-live-YOUR-KEY-HERE
curl https://api.minirouter.sh/v1/chat/completions \
  -H "Authorization: Bearer $MINIROUTER_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"zai/glm-5.3-flash","messages":[{"role":"user","content":"ping"}]}'
```

> **Tip:** Give Agnai its own key, so its spend shows separately in [Usage](https://minirouter.sh/dashboard/usage) and a limit stops only Agnai.

### 3. Create the preset

Open Settings → AI Settings → Third-Party preset and fill in:

| Setting | Value |
| --- | --- |
| `AI Service` | Third-Party |
| `Third Party Format` | OpenAI Compat (Chat) |
| `Third Party URL` | `https://api.minirouter.sh/v1`. Never append /chat/completions — Agnai adds the path itself. |
| `Third Party Key/Password` | `mr-live-… (your key)` |
| `OpenAI Model Override` | `zai/glm-5.3-flash` |

> **Warning:** Leave Disable Auto-URL off. Agnai then adds `/chat/completions` itself.

### 4. Send a message

Choose the preset from the chat menu's Preset and send a message. Open [Activity](https://minirouter.sh/dashboard/activity) to see its model, tokens and exact cost.

## Switch models

Open the model picker, type into Manual Model ID, then Confirm. Any model ID works.

| Model ID | Answers with |
| --- | --- |
| `minirouter/auto:roleplay` | A long-context, low-input-cost model [Auto](https://minirouter.sh/docs/auto-router) picks. |
| `@preset/your-slug` | Your saved [preset](https://minirouter.sh/docs/presets), with up to three models as [fallbacks](https://minirouter.sh/docs/model-fallbacks). |

## Two kinds of preset

| Preset | Holds |
| --- | --- |
| Agnai preset | Service, URL, key, model and samplers. Pick one per chat from the chat menu's Preset. |
| MiniRouter preset | Models and fallbacks on our side. Create one in [Presets](https://minirouter.sh/dashboard/presets), then send `@preset/your-slug` as the model. |

> **Note:** Agnai sends its own system prompt, which replaces a MiniRouter preset's saved instructions.

## Size each turn

| Setting | Does |
| --- | --- |
| Context Size | Most Agnai sends as the prompt. Lower it to cut input cost. |
| Response Length | Most the model writes back. |
| Stream Response | Shows the reply as it arrives. See [Streaming](https://minirouter.sh/docs/streaming). |

Keep Context Size below the window on the model's page in [Models](https://minirouter.sh/models). A prompt over the window fails with [`context_too_long`](https://minirouter.sh/docs/errors#context_too_long).

## Keep spend in check

- [Own key](https://minirouter.sh/dashboard/keys): One key for Agnai.
- [Spend cap](https://minirouter.sh/docs/rate-limits): Daily or monthly limit on that key.
- [Activity](https://minirouter.sh/dashboard/activity): Every request and its cost.

Every regenerate is a new, billed request.

## Recommended models

| Model | Why |
| --- | --- |
| [`zai/glm-5.3-flash`](https://minirouter.sh/models/zai/glm-5.3-flash) | Best current intelligence/input-cost balance with a 1M-token window. |
| [`openai/gpt-5.6-luna`](https://minirouter.sh/models/openai/gpt-5.6-luna) | High-intelligence alternative with a 1.05M-token window. |
| [`deepseek/deepseek-v4-flash-0731`](https://minirouter.sh/models/deepseek/deepseek-v4-flash-0731) | Lowest input rate on this list for repeatedly sent chat history. |
| [`google/gemini-3.8-flash`](https://minirouter.sh/models/google/gemini-3.8-flash) | Higher-cost multimodal alternative with a 1M-token window. |

Browse every model in the [catalog](https://minirouter.sh/models).

## Troubleshooting

### 404, HTML, or a parse error on every request

Almost always the base URL. Use https://api.minirouter.sh/v1 — the bare host without /v1 also works, but never append /chat/completions to the base URL field; the client adds that path itself.

Error: [400 `invalid_request`](https://minirouter.sh/docs/errors#invalid_request).

### 401 on every request

Wrong or rotated key. Keys start with mr-live-; after a rotation the old key keeps working for 24 hours, then dies.

Error: [401 `invalid_api_key`](https://minirouter.sh/docs/errors#invalid_api_key).

### Works self-hosted, fails on the hosted instance

The hosted app makes the request from its own servers unless Use Local Requests is enabled. Nothing on our side distinguishes the two — check the preset is actually selected for the character you are chatting with, since Agnai stores a preset per character.

### Response stops mid-sentence with a credits message

Balance hit $0 mid-stream. The stream ends with a terminal error naming the exact charge for tokens delivered — never a silent close.

Error: [402 `insufficient_credits`](https://minirouter.sh/docs/errors#insufficient_credits).

Every error code, with its fix: [Errors](https://minirouter.sh/docs/errors).

## Next steps

- [Roleplay](https://minirouter.sh/use/roleplay): Models, privacy and accountless use.
- [Cost per message](https://minirouter.sh/guides/roleplay-cost-per-message): What a long chat costs.
- [Presets](https://minirouter.sh/docs/presets): Save a model and its settings under one name.
