Features
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.
Install the Anthropic SDK
Section titled “Install the Anthropic SDK”pip install anthropicConfigure the client
Section titled “Configure the client”Set the base_url to Infercom’s API and provide your Infercom API key.
import anthropic
client = anthropic.Anthropic( base_url="https://api.infercom.ai", api_key="your-infercom-api-key")Basic usage
Section titled “Basic usage”Non-streaming example
Section titled “Non-streaming example”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(next(block.text for block in message.content if block.type == "text"))gpt-oss-120b returns a thinking block before the text block, so select the text block by its type. content[0].text raises an AttributeError. See Reasoning (thinking blocks).
Streaming example
Section titled “Streaming example”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
Section titled “System prompts”Use the system parameter to provide instructions to the model.
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
Section titled “Multi-turn conversations”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)
Section titled “Tool use (function calling)”The Anthropic Messages API supports tool use for models that have function calling capabilities.
Defining tools
Section titled “Defining tools”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:
[ { "type": "tool_use", "id": "call_abc123", "name": "get_weather", "input": {"location": "Munich, Germany"} }]Providing tool results
Section titled “Providing tool results”After executing the tool, send the result back to continue the conversation:
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(next(block.text for block in message.content if block.type == "text"))Images
Section titled “Images”gemma-4-31B-it accepts images as base64 image blocks. A URL image source returns HTTP 400. gpt-oss-120b is text only and returns HTTP 400 for an image.
import base64
with open("sample.jpg", "rb") as image_file: image_base64 = base64.b64encode(image_file.read()).decode("utf-8")
message = client.messages.create( model="gemma-4-31B-it", max_tokens=1024, messages=[ { "role": "user", "content": [ { "type": "image", "source": {"type": "base64", "media_type": "image/jpeg", "data": image_base64} }, {"type": "text", "text": "What is happening in this image?"} ] } ])
print(next(block.text for block in message.content if block.type == "text"))Supported formats and the token cost per image: Vision.
Reasoning (thinking blocks)
Section titled “Reasoning (thinking blocks)”gpt-oss-120b and MiniMax-M3.1-Flash return their reasoning as a thinking block before the text block. They do this with or without the thinking parameter. gemma-4-31B-it returns no thinking block.
On gpt-oss-120b, budget_tokens selects one of three reasoning levels. It does not set an exact token limit.
budget_tokens |
Reasoning level |
|---|---|
| Up to 4,096 | low |
| 4,097 to 16,384 | medium, the same as without the thinking parameter |
| 16,385 and above | high |
thinking: {"type": "disabled"} does not turn reasoning off. Reasoning tokens count toward max_tokens: see Budgeting tokens for reasoning.
message = client.messages.create( model="gpt-oss-120b", max_tokens=4096, thinking={"type": "enabled", "budget_tokens": 1024}, messages=[{"role": "user", "content": "What is 27 * 43?"}])
for block in message.content: if block.type == "thinking": print("Thinking:", block.thinking) elif block.type == "text": print("Answer:", block.text)Async usage
Section titled “Async usage”import anthropicimport 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(next(block.text for block in message.content if block.type == "text"))
asyncio.run(main())Using curl
Section titled “Using curl”You can also call the Messages API directly with curl:
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
Section titled “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, 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) |
thinking |
object | Accepted. On gpt-oss-120b, budget_tokens selects the reasoning level. See Reasoning (thinking blocks) |
The Anthropic Python SDK 2.x has no temperature, top_p or top_k arguments. Pass them in extra_body, for example extra_body={"temperature": 0.7}.
Unsupported features
Section titled “Unsupported features”The following Anthropic-specific features are not supported:
- Prompt caching (
cache_control) - URL image sources (use base64, see Images)
- PDF file inputs
- Citations
- Server-side tools (web search, code execution)
- Batch API
repetition_penalty(returns HTTP 400 on this endpoint; use/v1/chat/completions)
Differences from Anthropic’s API
Section titled “Differences from Anthropic’s API”| Aspect | Anthropic | Infercom |
|---|---|---|
| Models | Claude (Opus, Sonnet, Haiku) | Open-weight models. EU sovereign: gpt-oss-120b, gemma-4-31B-it. Global Model Catalog (processed outside the EU): MiniMax-M3.1-Flash |
| 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
Section titled “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:
{ "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 for the shapes the other endpoints use.
When to use Anthropic vs OpenAI compatibility
Section titled “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 (/v1/responses) |
| New projects | Any - all three APIs work with the same models |
Related documentation
Section titled “Related documentation”- OpenAI compatibility - Using the OpenAI SDK
- Function calling - Detailed guide on tool use
- Responses API - Agentic workflows with structured outputs
- Supported models - Available models and capabilities