# Integrations

> Connect any OpenAI-, Anthropic-, or Gemini-compatible tool to MirAPI by setting its base URL, API key, and model name.

MirAPI speaks the three mainstream protocols — OpenAI, Anthropic, and Gemini — so almost any tool that can call a large language model can be pointed at MirAPI. In most tools you change exactly three things: the base URL, the API key, and the model name.

## What you need

| Element | Value |
|---|---|
| API key | `MIRAPI_API_KEY`, created in https://console.mirapi.ai → **API Keys** |
| Model name | `deepseek-chat` — the exact `id` returned by `GET /v1/models` |
| Base URL | depends on the protocol, see below |

A minimal OpenAI-compatible request confirms the three are wired up correctly:

```bash
curl https://api.mirapi.ai/v1/chat/completions \
  -H "Authorization: Bearer $MIRAPI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-chat",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'
```

## Choosing the base URL

| Tool protocol | Base URL | Typical tools |
|---|---|---|
| OpenAI-compatible | `https://api.mirapi.ai/v1` | Cursor, Cline, Roo Code, Chatbox, LangChain, n8n, most SDKs |
| Anthropic | `https://api.mirapi.ai` (bare, no `/v1`) | Claude Code, Anthropic SDK |
| Gemini | `https://api.mirapi.ai` or `https://api.mirapi.ai/v1beta` | Gemini CLI, Google GenAI SDK |

One rule covers most tools: **if the tool appends `/chat/completions` (or any other path) to the base URL itself, enter `https://api.mirapi.ai/v1`**. If the tool expects the raw API origin — as Anthropic and Gemini clients do — enter `https://api.mirapi.ai` as-is.

## Authentication

| Protocol | Accepted header(s) |
|---|---|
| OpenAI-compatible | `Authorization: Bearer <key>` (a bare key also works) |
| Anthropic | `x-api-key` or `Authorization: Bearer` |
| Gemini | `x-goog-api-key` or `?key=` |

The same `MIRAPI_API_KEY` works across all three protocols, so you need only one key. The `Authorization` scheme is case-insensitive, and the `OpenAI-Organization` header is accepted but ignored — there is no per-organization isolation.

Each key can carry four constraints: a model whitelist (models outside it return **403**), a validity period, a quota cap, and an IP allowlist. A **401** means the key is missing, invalid, or unknown; a **403** means the key is valid but the request was rejected.

## Tools covered here

| Tool | Protocol | Page |
|---|---|---|
| Claude Code | Anthropic | [Claude Code](/docs/integrations/claude-code) |
| Codex CLI | OpenAI (Responses) | [Codex CLI](/docs/integrations/codex) |
| Cursor | OpenAI | [Cursor](/docs/integrations/cursor) |
| Cline / Roo Code | OpenAI | [Cline](/docs/integrations/cline) · [Roo Code](/docs/integrations/roo-code) |
| Gemini CLI | Gemini | [Gemini CLI](/docs/integrations/gemini-cli) |
| OpenCode | OpenAI | [OpenCode](/docs/integrations/opencode) |
| Continue | OpenAI | [Continue](/docs/integrations/continue) |
| Chatbox / Cherry Studio / LobeChat / NextChat | OpenAI | [Chatbox](/docs/integrations/chatbox) · [Cherry Studio](/docs/integrations/cherry-studio) · [LobeChat](/docs/integrations/lobe-chat) · [NextChat](/docs/integrations/nextchat) |
| Anthropic SDK | Anthropic | [Anthropic SDK](/docs/integrations/anthropic-sdk) |
| LangChain / LlamaIndex | OpenAI | [LangChain](/docs/integrations/langchain) · [LlamaIndex](/docs/integrations/llamaindex) |
| Vercel AI SDK | OpenAI | [Vercel AI SDK](/docs/integrations/vercel-ai-sdk) |
| Dify / n8n | OpenAI | [Dify](/docs/integrations/dify) · [n8n](/docs/integrations/n8n) |
| Immersive Translate | OpenAI | [Immersive Translate](/docs/integrations/immersive-translate) |

Every tool page follows the same shape: the essentials, configuration steps, a send-a-message check, tool-specific pitfalls, and related links.

## MCP servers

MCP (Model Context Protocol) servers run unchanged with MirAPI: they are tools your agent invokes locally or remotely, and only the model API goes through the gateway. Configure your agent (Claude Code, Cursor, Cline, …) with the MirAPI base URL and key exactly as described on its page, and its MCP tools keep working — nothing about the MCP servers themselves needs to change.

## Billing

All integrations share one prepaid USD balance. There is no subscription, monthly fee, or minimum spend, and the balance never expires. Text and multimodal chats bill per token, images per image, and video per second of output. When the balance runs out, requests return **403**; top up and the same key works again immediately.

## Troubleshooting

- **401** — the key is missing, invalid, or unknown. Regenerate it in the console and check the environment variable.
- **403** — the key is valid but the request was rejected. Most often the model is not on the key's whitelist or the balance is exhausted. Top up or check the key's constraints, then retry.
- **413** — the request is too large. Reduce the payload size.
- **429** — rate limited. Back off with jittered exponential delay (1s → 2s → 4s, cap ~30s) and retry; the gateway does not retry on your behalf, and no `Retry-After` header is sent.
- **500** — server or upstream error. Safe to retry idempotent requests.
- **Model not found** — the model name must match `GET /v1/models` exactly. Use the exact catalogue name, without the `vendor/` prefix.

Every error message ends with a request ID — include it in any support ticket.

## Related links

- [Quickstart](/docs/quickstart)
- [Configuration](/docs/configuration)
- [OpenAI compatibility](/docs/openai-compat)
- [Models and pricing](/docs/models)
- [Billing](/docs/billing)