---
name: anymodel-api
description: Calls Claude, GPT, Gemini and other models through the AnyModel OpenAI- and Anthropic-compatible API with one key, and wires existing code or agents to it. Use when the user wants to call an LLM from code, switch providers, or connect a tool to AnyModel.
---

# AnyModel API

AnyModel exposes many models (Claude, GPT, Gemini, DeepSeek, Kimi and others) behind one
endpoint and one key, billed per token from a single balance.

- Base URL: `https://anymodel.org/v1`
- Auth: `Authorization: Bearer $ANYMODEL_API_KEY` (or `x-api-key` for the Anthropic format)
- Key: created in the AnyModel dashboard after sign-up at https://anymodel.org/app/register

## Ground rules

1. Read the key from the environment (`ANYMODEL_API_KEY`). Never hardcode it, never print it,
   never commit it. If the project has a `.env.example`, add the variable name there without a value.
2. Do not guess model ids. List them first and pick from the response:

   ```bash
   curl -s https://anymodel.org/v1/models \
     -H "Authorization: Bearer $ANYMODEL_API_KEY" | jq -r '.data[].id'
   ```

3. Prefer the format the code already uses. Code on the OpenAI SDK keeps the OpenAI SDK and only
   changes the base URL and key; code on the Anthropic SDK keeps the Anthropic SDK.

## OpenAI format (`/v1/chat/completions`, `/v1/responses`)

```bash
curl -s https://anymodel.org/v1/chat/completions \
  -H "Authorization: Bearer $ANYMODEL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "<model-id>", "messages": [{"role": "user", "content": "Hello"}]}'
```

Python (official `openai` package):

```python
import os
from openai import OpenAI

client = OpenAI(base_url="https://anymodel.org/v1", api_key=os.environ["ANYMODEL_API_KEY"])
reply = client.chat.completions.create(
    model="<model-id>",
    messages=[{"role": "user", "content": "Hello"}],
)
print(reply.choices[0].message.content)
```

Node (official `openai` package):

```js
import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://anymodel.org/v1", apiKey: process.env.ANYMODEL_API_KEY });
const reply = await client.chat.completions.create({
  model: "<model-id>",
  messages: [{ role: "user", content: "Hello" }],
});
console.log(reply.choices[0].message.content);
```

Streaming works the usual way (`stream: true`); handle the stream exactly as with the vendor API.

## Anthropic format (`/v1/messages`)

```python
import os
from anthropic import Anthropic

client = Anthropic(base_url="https://anymodel.org", api_key=os.environ["ANYMODEL_API_KEY"])
msg = client.messages.create(
    model="<model-id>",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}],
)
print(msg.content[0].text)
```

The Anthropic SDK appends `/v1/messages` itself, so its base URL is the host without `/v1`.

## Connecting a coding agent

AnyModel ships a one-line installer that writes the agent's config. The key is passed at run time:

```bash
# macOS / Linux; tool = claude | codex | opencode | cursor | zed | cline | kilo | copilot | droid
bash <(curl -fsSL "https://anymodel.org/i?tool=claude") "$ANYMODEL_API_KEY"
```

```powershell
# Windows PowerShell
$env:AM_KEY = $env:ANYMODEL_API_KEY; irm "https://anymodel.org/i?os=windows&tool=claude" | iex
```

Run the installer only after the user confirms: it rewrites the agent's config in the home directory
(a .bak copy is kept). Read the script first if the user asks what it changes. For tools without an
installer (Windsurf and other OpenAI-compatible clients) add a custom OpenAI-compatible provider
with base URL `https://anymodel.org/v1`, the key, and a model id from `/v1/models`.

## Checking the balance

```bash
curl -s https://anymodel.org/v1/balance -H "Authorization: Bearer $ANYMODEL_API_KEY"
```

## Errors

- `401` — missing or wrong key: check the variable is exported in the same shell or process.
  A 401 whose message says the balance has run out is a balance problem: top up, the key is fine.
- `402` / balance errors — top up in the dashboard; do not retry in a loop.
- `403 Account is blocked` / `403 Account is inactive` — the account behind the key is not active.
  No code or key change fixes it: stop retrying and tell the user to contact AnyModel support.
- `400 Invalid model` / `404 … The model is not configured` — the id is not in `/v1/models`; list
  again and pick an existing one.
- `429` / `5xx` — retry with exponential backoff and jitter, at most a few times.

## Report back

Tell the user which files changed, which variable they must set (`ANYMODEL_API_KEY`), which model
id was chosen and why, and the exact command you ran to verify the call worked.

Source: [AnyModel skills catalog](https://anymodel.org/en/skills) · License: [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
