> ## Documentation Index
> Fetch the complete documentation index at: https://docs.anannas.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Anthropic API Compatibility

> Use Anannas with Anthropic-compatible tools and SDKs

## Overview

Anannas provides full compatibility with the Anthropic Messages API format, allowing you to use Anannas with any tool or SDK designed for Anthropic's API. This includes Claude Code, the official Anthropic SDK, and other tools in the Anthropic ecosystem.

The `/v1/messages` endpoint converts Anthropic Messages API requests to Anannas' internal format and works with **all models** that Anannas supports, not just Anthropic models. You can use any model (OpenAI, Google, Anthropic, etc.) through this endpoint by specifying the model in Anannas' `provider/model-name` format.

## Base URL

The Anannas Anthropic-compatible endpoint is available at:

```
https://api.anannas.ai/v1/messages
```

Alternatively, you can use:

```
https://api.anannas.ai/api/v1/messages
```

## Authentication

All requests require a Bearer token in the `Authorization` header using your Anannas API key:

```bash theme={null}
Authorization: Bearer <ANANNAS_API_KEY>
```

Get your API key from the [Anannas dashboard](https://anannas.ai/dashboard).

## Model IDs

The `/v1/messages` endpoint accepts **any model** that Anannas supports, not just Anthropic models. Specify models using Anannas' standard `provider/model-name` format. The API will automatically route to the appropriate provider.

### Example Models from Different Providers

**OpenAI Models:**

* `gpt-4.1-mini`
* `gpt-5-mini`

**Google Models:**

* `gemini-2.5-pro`
* `gemini-2.5-flash`

**Other Providers:**

* `grok-4-1-fast-non-reasoning-latest`
* `mistralai/mistral-large`
* `meta-llama/llama-3-70b`
* And many more...

For a complete list of available models, visit [anannas.ai/models](https://anannas.ai/models) or query `GET https://api.anannas.ai/v1/models`.

<Note>
  The endpoint converts Anthropic Messages API format to Anannas' internal format, allowing you to use any supported model through the Anthropic-compatible interface. Model routing and provider selection are handled automatically.
</Note>

## Using Claude Code

Claude Code is an agentic coding tool that lives in your terminal and helps you code faster through natural language commands. You can configure Claude Code to use Anannas instead of the default Anthropic API.

### Step 1: Install Claude Code

```bash theme={null}
npm install -g @anthropic-ai/claude-code
```

<Note>
  If you encounter permission issues during installation, try using `sudo` (macOS/Linux) or running the command prompt as an administrator (Windows).
</Note>

### Step 2: Configure Environment Variables

Set up environment variables to point Claude Code to Anannas:

**macOS/Linux:**

```bash theme={null}
export ANTHROPIC_BASE_URL=https://api.anannas.ai
export ANTHROPIC_AUTH_TOKEN=<ANANNAS_API_KEY>
export API_TIMEOUT_MS=600000
export ANTHROPIC_MODEL=grok-4-1-fast-non-reasoning-latest
export ANTHROPIC_SMALL_FAST_MODEL=gpt-5-mini
export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
```

**Windows (PowerShell):**

```powershell theme={null}
$env:ANTHROPIC_BASE_URL="https://api.anannas.ai"
$env:ANTHROPIC_AUTH_TOKEN="<ANANNAS_API_KEY>"
$env:API_TIMEOUT_MS="600000"
$env:ANTHROPIC_MODEL="grok-4-1-fast-non-reasoning-latest"
$env:ANTHROPIC_SMALL_FAST_MODEL="gpt-5-mini"
$env:CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC="1"
```

**Windows (Command Prompt):**

```cmd theme={null}
set ANTHROPIC_BASE_URL=https://api.anannas.ai
set ANTHROPIC_AUTH_TOKEN=<ANANNAS_API_KEY>
set API_TIMEOUT_MS=600000
set ANTHROPIC_MODEL=grok-4-1-fast-non-reasoning-latest
set ANTHROPIC_SMALL_FAST_MODEL=gpt-5-mini
set CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
```

<Note>
  The `API_TIMEOUT_MS` parameter is configured to prevent excessively long outputs that could cause the Claude Code client to time out. Here, we set the timeout duration to 10 minutes (600000ms).
</Note>

### Step 3: Start Claude Code

Navigate to your project directory and run:

```bash theme={null}
cd your-project
claude
```

If prompted with "Do you want to use this API key," select "Yes."

After launching, grant Claude Code permission to access files in your folder. You can now use Claude Code with Anannas.

### Model Configuration

Claude Code uses internal model environment variables that map to specific models. The default configuration maps:

* `ANTHROPIC_DEFAULT_OPUS_MODEL`: Maps to Claude Code's "opus" tier (most capable)
* `ANTHROPIC_DEFAULT_SONNET_MODEL`: Maps to Claude Code's "sonnet" tier (balanced)
* `ANTHROPIC_DEFAULT_HAIKU_MODEL`: Maps to Claude Code's "haiku" tier (fastest)

You can customize these mappings to use any Anannas-supported model. For example, you could use OpenAI models:

```bash theme={null}
export ANTHROPIC_DEFAULT_OPUS_MODEL=gpt-4.1-mini
export ANTHROPIC_DEFAULT_SONNET_MODEL=grok-4-1-fast-non-reasoning-latest
export ANTHROPIC_DEFAULT_HAIKU_MODEL=gpt-5-mini
```

Or mix providers:

```bash theme={null}
export ANTHROPIC_DEFAULT_OPUS_MODEL=anthropic/claude-opus-4
export ANTHROPIC_DEFAULT_SONNET_MODEL=grok-4-1-fast-non-reasoning-latest
export ANTHROPIC_DEFAULT_HAIKU_MODEL=gemini-2.5-flash
```

Alternatively, you can configure model mappings in Claude Code's settings file (`~/.claude/settings.json`):

```json theme={null}
{
  "env": {
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "gpt-5-mini",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "grok-4-1-fast-non-reasoning-latest",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "gpt-4.1-mini"
  }
}
```

<Note>
  It is generally not recommended to manually adjust the model mapping, as hardcoding the model mapping makes it inconvenient to automatically update to the latest model when Anannas adds new models. If you want to use the latest default mappings, simply delete the model mapping configuration in settings.json.
</Note>

## Using the Anthropic SDK

You can use the official Anthropic SDK with Anannas by configuring the base URL.

### Step 1: Install the Anthropic SDK

**Python:**

```bash theme={null}
pip install anthropic
```

**Node.js:**

```bash theme={null}
npm install @anthropic-ai/sdk
```

### Step 2: Configure the Client

**Python:**

```python theme={null}
import anthropic

client = anthropic.Anthropic(
    base_url="https://api.anannas.ai/v1",
    api_key="<ANANNAS_API_KEY>"
)
```

**Node.js:**

```typescript theme={null}
import Anthropic from '@anthropic-ai/sdk';

const client = new Anthropic({
  baseURL: 'https://api.anannas.ai/v1',
  apiKey: '<ANANNAS_API_KEY>',
});
```

### Step 3: Make API Calls

**Python:**

```python theme={null}
message = client.messages.create(
    model="grok-4-1-fast-non-reasoning-latest",
    max_tokens=1000,
    system="You are a helpful assistant.",
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": "Hi, how are you?"
                }
            ]
        }
    ]
)

print(message.content)
```

**Node.js:**

```typescript theme={null}
const message = await client.messages.create({
  model: 'grok-4-1-fast-non-reasoning-latest',
  max_tokens: 1000,
  system: 'You are a helpful assistant.',
  messages: [
    {
      role: 'user',
      content: [
        {
          type: 'text',
          text: 'Hi, how are you?',
        },
      ],
    },
  ],
});

console.log(message.content);
```

## Direct HTTP Requests

You can also make direct HTTP requests to the endpoint:

<CodeGroup>
  ```python python theme={null}
  import requests

  response = requests.post(
      "https://api.anannas.ai/v1/messages",
      headers={
          "Authorization": "Bearer <ANANNAS_API_KEY>",
          "Content-Type": "application/json",
          "anthropic-version": "2023-06-01"
      },
      json={
          "model": "grok-4-1-fast-non-reasoning-latest",
          "max_tokens": 1000,
          "system": "You are a helpful assistant.",
          "messages": [
              {
                  "role": "user",
                  "content": [
                      {
                          "type": "text",
                          "text": "Explain quantum computing in simple terms"
                      }
                  ]
              }
          ]
      }
  )

  data = response.json()
  print(data["content"][0]["text"])
  ```

  ```typescript typescript theme={null}
  const response = await fetch('https://api.anannas.ai/v1/messages', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer <ANANNAS_API_KEY>',
      'Content-Type': 'application/json',
      'anthropic-version': '2023-06-01',
    },
    body: JSON.stringify({
      model: 'grok-4-1-fast-non-reasoning-latest',
      max_tokens: 1000,
      system: 'You are a helpful assistant.',
      messages: [
        {
          role: 'user',
          content: [
            {
              type: 'text',
              text: 'Explain quantum computing in simple terms',
            },
          ],
        },
      ],
    }),
  });

  const data = await response.json();
  console.log(data.content[0].text);
  ```

  ```bash bash theme={null}
  curl https://api.anannas.ai/v1/messages \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $ANANNAS_API_KEY" \
    -H "anthropic-version: 2023-06-01" \
    -d '{
      "model": "grok-4-1-fast-non-reasoning-latest",
      "max_tokens": 1000,
      "system": "You are a helpful assistant.",
      "messages": [
        {
          "role": "user",
          "content": [
            {
              "type": "text",
              "text": "Explain quantum computing in simple terms"
            }
          ]
        }
      ]
    }'
  ```
</CodeGroup>

## API Compatibility Details

### HTTP Headers

| Field               | Support Status                                        |
| ------------------- | ----------------------------------------------------- |
| `anthropic-beta`    | Ignored                                               |
| `anthropic-version` | Ignored                                               |
| `x-api-key`         | Fully Supported (use `Authorization: Bearer` instead) |
| `Authorization`     | Fully Supported                                       |

### Request Fields

| Field            | Support Status      | Notes                                                                                                                                                      |
| ---------------- | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `model`          | Fully Supported     | Use any Anannas model format (e.g., `grok-4-1-fast-non-reasoning-latest`, `anthropic/claude-4.5-sonnet`, `gemini-2.5-pro`)                                 |
| `max_tokens`     | Fully Supported     | Required field                                                                                                                                             |
| `messages`       | Fully Supported     | Required field, minimum 1 message                                                                                                                          |
| `system`         | Supported           | String or array of system blocks (cache\_control in array blocks is not preserved)                                                                         |
| `temperature`    | Fully Supported     | Range \[0.0 \~ 2.0]                                                                                                                                        |
| `top_p`          | Fully Supported     | Range \[0.0 \~ 1.0]                                                                                                                                        |
| `top_k`          | Ignored             | Not supported by all models. Not allowed when `thinking` is enabled                                                                                        |
| `stop_sequences` | Fully Supported     | Array of stop sequences                                                                                                                                    |
| `stream`         | Fully Supported     | Server-Sent Events (SSE)                                                                                                                                   |
| `tools`          | Fully Supported     | Tool definitions for function calling                                                                                                                      |
| `tool_choice`    | Fully Supported     | `none`, `auto`, `any`, or specific tool. When `thinking` is enabled, only `"auto"` or `"none"` are allowed                                                 |
| `thinking`       | Supported           | `budget_tokens` is converted to `reasoning.max_tokens`. Interleaved thinking is automatically enabled when tools are present and `tool_choice` is `"auto"` |
| `metadata`       | Partially Supported | `user_id` is supported                                                                                                                                     |

### Tool Fields

| Field           | Support Status  |                                  |
| --------------- | --------------- | -------------------------------- |
| `name`          | Fully Supported |                                  |
| `description`   | Fully Supported |                                  |
| `input_schema`  | Fully Supported |                                  |
| `cache_control` | Supported       | Prompt caching support for tools |

### Tool Choice Values

| Value  | Support Status  | Notes                                                                                                |
| ------ | --------------- | ---------------------------------------------------------------------------------------------------- |
| `none` | Fully Supported |                                                                                                      |
| `auto` | Supported       | `disable_parallel_tool_use` is ignored. Required for interleaved thinking when `thinking` is enabled |
| `any`  | Supported       | `disable_parallel_tool_use` is ignored. Not allowed when `thinking` is enabled                       |
| `tool` | Supported       | `disable_parallel_tool_use` is ignored. Not allowed when `thinking` is enabled                       |

### Message Content Types

| Content Type        | Support Status  | Notes                                                          |
| ------------------- | --------------- | -------------------------------------------------------------- |
| `text`              | Fully Supported | String or content block                                        |
| `image`             | Supported       | Base64-encoded images                                          |
| `tool_use`          | Fully Supported | Tool call from assistant                                       |
| `tool_result`       | Fully Supported | Tool result from user                                          |
| `thinking`          | Supported       | Reasoning/thinking blocks                                      |
| `document`          | Not Supported   |                                                                |
| `search_result`     | Not Supported   |                                                                |
| `redacted_thinking` | Supported       | Redacted/encrypted thinking blocks are supported and preserved |
| `server_tool_use`   | Not Supported   |                                                                |
| `mcp_tool_use`      | Not Supported   |                                                                |

### Response Format

Responses follow the Anthropic Messages API format:

```json theme={null}
{
  "id": "msg_abc123",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "Response text here"
    }
  ],
  "model": "grok-4-1-fast-non-reasoning-latest",
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 10,
    "output_tokens": 50
  }
}
```

### Streaming

When `stream: true` is set, the API returns Server-Sent Events (SSE) with the following event types:

* `message_start`: Initial message metadata
* `content_block_start`: Start of a content block
* `content_block_delta`: Incremental content updates
* `content_block_stop`: End of a content block
* `message_delta`: Message-level updates (stop\_reason, usage)
* `message_stop`: End of the message stream
* `ping`: Keep-alive heartbeat events
* `error`: Error events

## Troubleshooting

### Claude Code Configuration Not Working

If you manually modified the `~/.claude/settings.json` configuration file but found the changes did not take effect:

1. Close all Claude Code windows, open a new command-line window, and run `claude` again
2. If the issue persists, try deleting the `~/.claude/settings.json` file and then reconfigure the environment variables
3. Confirm that the JSON format of the configuration file is correct - check variable names and ensure there are no missing or extra commas

### Model Not Found Errors

If you receive a "model not found" error:

1. Verify the model ID format is correct: `provider/model-name` (e.g., `grok-4-1-fast-non-reasoning-latest`, `anthropic/claude-3.7-sonnet`)
2. Check available models at [anannas.ai/models](https://anannas.ai/models) or via `GET https://api.anannas.ai/v1/models`
3. Ensure your API key has access to the requested model
4. Remember: you can use any model supported by Anannas, not just Anthropic models

### Authentication Errors

If you receive authentication errors:

1. Verify your API key is correct and active in the [Anannas dashboard](https://anannas.ai/dashboard)
2. Ensure you're using `Authorization: Bearer <ANANNAS_API_KEY>` header format
3. Check that your API key has sufficient credits

## Next Steps

* Explore [Streaming](/API/Streaming) for real-time responses
* Learn about [Tool Calling](/Features/tool-calling) for function execution
* Review [Reasoning](/UseCases/reasoning) for thinking/reasoning capabilities
* Check [Authentication](/API/Authentication) for security best practices
