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

# Implement Anthropic-Compatible Features - Developer Guide

> Use the Anthropic SDK and Messages API with the Infercom API. Drop-in compatible - just change the base URL and API key to switch to EU sovereign inference.

The Infercom API supports Anthropic's Messages API format (`/v1/messages`), enabling you to use the Anthropic Python SDK and compatible tooling with Infercom's models. This is useful for applications and frameworks built around the Anthropic API, such as Claude Code, LangChain's Anthropic provider, or custom agentic workflows.

<Aside type="note">
  The Anthropic SDK was designed for Claude models. When using it with Infercom, you're accessing open-source models (like gpt-oss, Gemma, DeepSeek) through an Anthropic-compatible interface - not Claude itself.
</Aside>

## Install the Anthropic SDK

```bash
pip install anthropic
```

## Configure the client

Set the `base_url` to Infercom's API and provide your Infercom API key.

<Aside type="note">
  Don't have an Infercom API key? Get yours from the [API keys and URLs](/en/get-started/api-keys-urls) page.
</Aside>

```python
import anthropic

client = anthropic.Anthropic(
    base_url="https://api.infercom.ai",
    api_key="your-infercom-api-key"
)
```

## Basic usage

### Non-streaming example

```python
import anthropic

client = anthropic.Anthropic(
    base_url="https://api.infercom.ai",
    api_key="your-infercom-api-key"
)

message = client.messages.create(
    model="gpt-oss-120b",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "What is the capital of Germany?"}
    ]
)

print(message.content[0].text)
```

### Streaming example

```python
import anthropic

client = anthropic.Anthropic(
    base_url="https://api.infercom.ai",
    api_key="your-infercom-api-key"
)

with client.messages.stream(
    model="gpt-oss-120b",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "Write a haiku about AI."}
    ]
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)
```

### System prompts

Use the `system` parameter to provide instructions to the model.

```python
message = client.messages.create(
    model="gpt-oss-120b",
    max_tokens=1024,
    system="You are a helpful assistant that speaks like a pirate.",
    messages=[
        {"role": "user", "content": "Hello!"}
    ]
)
```

### Multi-turn conversations

```python
message = client.messages.create(
    model="gpt-oss-120b",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "My name is Thomas."},
        {"role": "assistant", "content": "Nice to meet you, Thomas!"},
        {"role": "user", "content": "What is my name?"}
    ]
)
```

## Tool use (function calling)

The Anthropic Messages API supports tool use for models that have function calling capabilities.

<Aside type="note">
  Tool use works with `gpt-oss-120b`. Other models may not reliably call tools. See [Function calling](/en/features/function-calling) for model-specific guidance.
</Aside>

### Defining tools

```python
import anthropic

client = anthropic.Anthropic(
    base_url="https://api.infercom.ai",
    api_key="your-infercom-api-key"
)

message = client.messages.create(
    model="gpt-oss-120b",
    max_tokens=200,
    tools=[
        {
            "name": "get_weather",
            "description": "Get the current weather in a given location",
            "input_schema": {
                "type": "object",
                "properties": {
                    "location": {
                        "type": "string",
                        "description": "The city and country, e.g. Munich, Germany"
                    }
                },
                "required": ["location"]
            }
        }
    ],
    messages=[
        {"role": "user", "content": "What's the weather in Munich?"}
    ]
)

print(message.content)
```

If the model decides to use the tool, the response will include a `tool_use` content block:

```json
[
  {
    "type": "tool_use",
    "id": "call_abc123",
    "name": "get_weather",
    "input": {"location": "Munich, Germany"}
  }
]
```

### Providing tool results

After executing the tool, send the result back to continue the conversation:

```python
message = client.messages.create(
    model="gpt-oss-120b",
    max_tokens=200,
    tools=[
        {
            "name": "get_weather",
            "description": "Get the current weather in a given location",
            "input_schema": {
                "type": "object",
                "properties": {
                    "location": {"type": "string"}
                },
                "required": ["location"]
            }
        }
    ],
    messages=[
        {"role": "user", "content": "What's the weather in Munich?"},
        {
            "role": "assistant",
            "content": [
                {
                    "type": "tool_use",
                    "id": "call_abc123",
                    "name": "get_weather",
                    "input": {"location": "Munich, Germany"}
                }
            ]
        },
        {
            "role": "user",
            "content": [
                {
                    "type": "tool_result",
                    "tool_use_id": "call_abc123",
                    "content": "Sunny, 22°C"
                }
            ]
        }
    ]
)

print(message.content[0].text)
```

## Async usage

```python
import anthropic
import asyncio

async def main():
    client = anthropic.AsyncAnthropic(
        base_url="https://api.infercom.ai",
        api_key="your-infercom-api-key"
    )

    message = await client.messages.create(
        model="gpt-oss-120b",
        max_tokens=1024,
        messages=[
            {"role": "user", "content": "Hello!"}
        ]
    )
    print(message.content[0].text)

asyncio.run(main())
```

## Using curl

You can also call the Messages API directly with curl:

```bash
curl https://api.infercom.ai/v1/messages \
  -H "Content-Type: application/json" \
  -H "x-api-key: your-infercom-api-key" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "gpt-oss-120b",
    "max_tokens": 1024,
    "messages": [
      {"role": "user", "content": "Hello!"}
    ]
  }'
```

## Supported parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `model` | string | Required. The model to use (e.g., `gpt-oss-120b`) |
| `messages` | array | Required. Array of message objects with `role` and `content` |
| `max_tokens` | integer | Required. Maximum tokens to generate |
| `system` | string | System prompt for the model |
| `temperature` | number | Sampling temperature (0.0-2.0). [No default](/en/models/infercomcloud-models#if-you-omit-temperature), unlike the Anthropic API, which defaults to 1.0. |
| `top_p` | number | Nucleus sampling parameter |
| `top_k` | integer | Top-k sampling parameter |
| `stop_sequences` | array | Custom stop sequences |
| `stream` | boolean | Enable streaming responses |
| `tools` | array | Tool definitions for function calling |
| `tool_choice` | object | Control tool usage (`auto`, `any`, or specific tool) |

## Unsupported features

The following Anthropic-specific features are not supported:

- Extended thinking (`thinking` parameter)
- Prompt caching (`cache_control`)
- Vision/image inputs
- PDF file inputs
- Citations
- Server-side tools (web search, code execution)
- Batch API
- `repetition_penalty` (accepted and ignored on this endpoint, and an upcoming platform release will reject it; use `/v1/chat/completions`)

## Differences from Anthropic's API

| Aspect | Anthropic | Infercom |
|--------|-----------|----------|
| Models | Claude (Opus, Sonnet, Haiku) | Open-source models (gpt-oss, Gemma, DeepSeek, Llama) |
| Base URL | `https://api.anthropic.com` | `https://api.infercom.ai` |
| API key header | `x-api-key` | `x-api-key` (same) |
| Version header | Required: `anthropic-version` | Supported but optional |
| Error shape | Anthropic error format | Anthropic error format (see below) |

### Error responses

`/v1/messages` returns errors in the **Anthropic** shape, not the OpenAI envelope used by Infercom's other endpoints. The body carries a top-level `"type": "error"`, and the `error` object holds `message` and `type` only:

```json
{
  "type": "error",
  "error": {
    "type": "not_found_error",
    "message": "The model `nonexistent-model` does not exist or you do not have access to it."
  },
  "request_id": "req_6313f64378ad4a89b6005ab233a3f2a9"
}
```

| Field | Notes |
| :---- | :---- |
| `type` (top level) | Always `error` |
| `error.type` | `authentication_error`, `invalid_request_error` or `not_found_error` |
| `error.message` | Human-readable explanation |
| `error.param` / `error.code` | **Not returned.** The OpenAI-compatible endpoints provide these; `/v1/messages` does not |
| `request_id` | Present on every status. Most carry a `req_` prefix; the 401 does not |

This shape is returned for every error status, including 400, 401, 404, 410 and 422. See [API error codes](/en/api-reference/using-the-api/api-error-codes) for the shapes the other endpoints use.

## When to use Anthropic vs OpenAI compatibility

| Use case | Recommended API |
|----------|-----------------|
| Existing Anthropic SDK code | Anthropic Messages API (`/v1/messages`) |
| Claude Code, LangChain Anthropic | Anthropic Messages API (`/v1/messages`) |
| OpenAI SDK code | OpenAI Chat Completions API (`/v1/chat/completions`) |
| Agentic workflows, coding tools | [Responses API](/en/features/responses-api) (`/v1/responses`) |
| New projects | Any - all three APIs work with the same models |

## Related documentation

- [OpenAI compatibility](/en/features/openai-compatibility) - Using the OpenAI SDK
- [Function calling](/en/features/function-calling) - Detailed guide on tool use
- [Responses API](/en/features/responses-api) - Agentic workflows with structured outputs
- [Supported models](/en/models/infercomcloud-models) - Available models and capabilities
