> For the complete documentation index, see [llms.txt](https://docs.avis.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.avis.xyz/api-reference/introduction/anthropic-compatibility.md).

# Anthropic Compatibility

Point the official `@anthropic-ai/sdk` — or Claude Code/Claude Desktop's custom endpoint config — at Avis. Set your real Avis API key in `apiKey` (see Authentication).

### Base URL

```
https://api.avis.xyz/api/anthropic
```

### Switching an existing app

```typescript
import Anthropic from '@anthropic-ai/sdk'

const client = new Anthropic({
  apiKey: process.env.AVIS_API_KEY,
  baseURL: 'https://api.avis.xyz/api/anthropic',
})
```

Existing Messages API calls need no other changes. Embeddings use the Avis extension documented below because Anthropic does not define an embeddings resource in its API or SDK.

### Endpoints

| Method | Path                           | Streaming | Description                                   |
| ------ | ------------------------------ | --------- | --------------------------------------------- |
| `HEAD` | `/api/anthropic`               | —         | Connectivity probe (no auth)                  |
| `GET`  | `/api/anthropic/v1/models`     | —         | List available models                         |
| `POST` | `/api/anthropic/v1/messages`   | ✅         | Messages API                                  |
| `POST` | `/api/anthropic/v1/embeddings` | —         | Avis embeddings extension; float vectors only |

`anthropic-version` and `anthropic-beta` request headers are forwarded to the upstream provider when present — see Authentication.

#### `POST /messages`

```typescript
const response = await client.messages.create({
  model: 'anthropic/claude-sonnet-4-5',
  max_tokens: 1024,
  messages: [{ role: 'user', content: 'Hello!' }],
})
console.log(response.content[0].text)
```

#### `POST /embeddings` (Avis extension)

The Anthropic SDK has no `client.embeddings` resource. Use its low-level `post` method so the request still uses the configured Anthropic base URL, API key, retries, and headers:

```typescript
const response = await client.post<{ data: Array<{ embedding: number[] }> }>(
  '/v1/embeddings',
  {
    body: {
      model: 'text-embedding-3-small',
      input: ['first document', 'second document'],
      dimensions: 256,
      encoding_format: 'float',
    },
  },
)

console.log(response.data[0].embedding)
```

This extension returns the same `{ object, data, model, usage }` embedding-list shape as the OpenAI-compatible endpoint. It accepts text input and Avis normalized multimodal content blocks — `imageBase64`/`imageUrl`, `audioBase64`/`audioUrl`, `fileBase64`, and `videoBase64`:

```typescript
import { readFileSync } from 'node:fs'

const response = await client.post<{ data: Array<{ embedding: number[] }> }>('/v1/embeddings', {
  body: {
    model: 'voyage-multimodal-3-5',
    input: [
      {
        content: [
          { type: 'text', text: 'What is in this image?' },
          {
            type: 'imageBase64',
            data: readFileSync('image.png').toString('base64'),
            mediaType: 'image/png',
          },
        ],
      },
    ],
  },
})

console.log(response.data[0].embedding)
```

Or by URL, via `imageUrl`:

```typescript
const response = await client.post<{ data: Array<{ embedding: number[] }> }>('/v1/embeddings', {
  body: {
    model: 'voyage-multimodal-3-5',
    input: [
      {
        content: [
          { type: 'text', text: 'What is in this image?' },
          { type: 'imageUrl', url: 'https://example.com/image.png' },
        ],
      },
    ],
  },
})

console.log(response.data[0].embedding)
```

Audio is Gemini-exclusive (`gemini-embedding-2`/`gemini-embedding-2-preview` only), and accepts either base64 or a URL reference:

```typescript
const response = await client.post<{ data: Array<{ embedding: number[] }> }>('/v1/embeddings', {
  body: {
    model: 'gemini-embedding-2',
    input: [
      {
        content: [
          { type: 'text', text: 'Transcribe the sentiment of this clip.' },
          {
            type: 'audioBase64',
            data: readFileSync('clip.wav').toString('base64'),
            mediaType: 'audio/wav',
          },
        ],
      },
    ],
  },
})

console.log(response.data[0].embedding)
```

```typescript
const response = await client.post<{ data: Array<{ embedding: number[] }> }>('/v1/embeddings', {
  body: {
    model: 'gemini-embedding-2',
    input: [
      {
        content: [
          { type: 'text', text: 'Transcribe the sentiment of this clip.' },
          { type: 'audioUrl', url: 'https://example.com/clip.wav' },
        ],
      },
    ],
  },
})

console.log(response.data[0].embedding)
```

For video (and PDF, via `fileBase64`), no URL variant exists — inline base64 is the only accepted source. Video embedding is available for models whose capability metadata allows it:

```typescript
import { readFileSync } from 'node:fs'

const response = await client.post<{ data: Array<{ embedding: number[] }> }>(
  '/v1/embeddings',
  {
    body: {
      model: 'gemini-embedding-2',
      dimensions: 128,
      input: [
        {
          content: [
            { type: 'text', text: 'Embed this video' },
            {
              type: 'videoBase64',
              data: readFileSync('clip.mp4').toString('base64'),
              mediaType: 'video/mp4',
            },
          ],
        },
      ],
    },
  },
)

console.log(response.data[0].embedding)
```

`videoBase64` is an Avis extension, not an Anthropic content-block type. Video remains restricted to `gemini-embedding-2` and `gemini-embedding-2-preview`; unsupported model/input combinations return 400.

#### `GET /models`

```typescript
const models = await fetch('https://api.avis.xyz/api/anthropic/v1/models', {
  headers: {
    Authorization: `Bearer ${process.env.AVIS_API_KEY}`,
  },
}).then((r) => r.json())

console.log(models.data[0])
```

### Field support

This proxy is a **thin pass-through**. Request fields mostly follow Anthropic-compatible upstream definitions and are forwarded as-is. Whether a field is honored depends on the resolved provider/model.

### `/models` response

| Field                                   | Type            | Required | Notes                                                                                                                                                       |
| --------------------------------------- | --------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `id`                                    | `string`        | ✅        | User-facing model ID used in `model` for Anthropic-compatible calls                                                                                         |
| `name`                                  | `string`        | —        | Human-readable model name                                                                                                                                   |
| `inputModalities`                       | `array<string>` | —        | Supported input modalities for the model                                                                                                                    |
| `outputModalities`                      | `array<string>` | —        | Supported output modalities for the model                                                                                                                   |
| `capabilitiesProviderId`                | `string`        | —        | Provider row selected by priority for capability resolution                                                                                                 |
| `capabilities`                          | `object`        | —        | Effective capability object for the priority-winning provider row. Absent means unconstrained.                                                              |
| `capabilities.text.supportedParameters` | `array<string>` | —        | For text models: accepted generation parameters (e.g. `maxTokens`, `temperature`, `topP`, `tools`, `thinking`).                                             |
| `capabilities.params`                   | `object`        | —        | Per-parameter bounds/constraints keyed by request field name. For image/video models, read from `capabilities.image.params` or `capabilities.video.params`. |
| `capabilities.inputs`                   | `object`        | —        | Accepted content-part inputs (roles, media types, limits).                                                                                                  |
| `capabilities.strictParams`             | `boolean`       | —        | When `true`, unsupported gated params are rejected.                                                                                                         |
| `chatPricing`                           | `object`        | —        | Effective chat pricing metadata for the selected provider row                                                                                               |
| `imagePricing`                          | `object`        | —        | Effective image pricing metadata for the selected provider row                                                                                              |
| `videoPricing`                          | `object`        | —        | Effective video pricing metadata for the selected provider row                                                                                              |
| `threeDPricing`                         | `object`        | —        | Effective 3D pricing metadata for the selected provider row                                                                                                 |
| `embeddingPricing`                      | `object`        | —        | Effective embedding pricing metadata for the selected provider row                                                                                          |

#### `capabilities.params` value shapes

For image/video models, use per-model `capabilities.image.params` or `capabilities.video.params` instead of hardcoding shared limits across models.

| `type`  | Extra fields                                          | Meaning                                                                                        |
| ------- | ----------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
| `enum`  | `values: string[]`, `default?`                        | Value must be one of `values`.                                                                 |
| `range` | `min`, `max`, `default?`, `unit?`, `steps?: number[]` | Value must be between `min` and `max`. When `steps` exists, only those exact values are valid. |
| `int`   | `min`, `max`, `default?`                              | Value must be an integer between `min` and `max`.                                              |
| `bool`  | `default?`                                            | Value must be `true` or `false`.                                                               |

### `/messages`

| Field            | Type            | Required | Notes                                                                             |
| ---------------- | --------------- | -------- | --------------------------------------------------------------------------------- |
| `model`          | `string`        | ✅        | Anthropic model ID; resolved and rewritten to provider model ID before forwarding |
| `max_tokens`     | `number`        | ✅        | Maximum tokens to generate                                                        |
| `messages`       | `array`         | ✅        | Standard Anthropic message array                                                  |
| `system`         | `string`        | —        | System prompt                                                                     |
| `temperature`    | `number`        | —        | Sampling temperature                                                              |
| `top_p`          | `number`        | —        | Nucleus sampling                                                                  |
| `top_k`          | `number`        | —        | Top-K sampling                                                                    |
| `stream`         | `boolean`       | —        | Enable streaming response                                                         |
| `tools`          | `array`         | —        | Tool definitions                                                                  |
| `tool_choice`    | `object`        | —        | Tool selection strategy                                                           |
| `stop_sequences` | `array<string>` | —        | Custom stop sequences                                                             |
| `metadata`       | `object`        | —        | Request metadata                                                                  |
| `thinking`       | `object`        | —        | Extended thinking configuration                                                   |

### `/messages` response

Response fields follow Anthropic-compatible shape and are passed through.

#### `stop_reason`

`stop_reason` indicates why the model stopped generating.

| Field         | Type                   | Required | Notes                                                       |
| ------------- | ---------------------- | -------- | ----------------------------------------------------------- |
| `stop_reason` | `enum<string> \| null` | Yes      | Pass-through value from upstream; no mapping/normalization. |

Available options:

* `end_turn`
* `max_tokens`
* `stop_sequence`
* `tool_use`
* `pause_turn`
* `refusal`
* `compaction`
* `null`


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.avis.xyz/api-reference/introduction/anthropic-compatibility.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
