# An Anthropic API compatible endpoint for open models: how to use it

If your code was written against Anthropic's Messages API, you don't have to rewrite it to try open models. Here's how an Anthropic API compatible endpoint works for Llama, Qwen, Gemma and gpt-oss, exactly which fields are supported, and where the OpenAI format is the better choice.

Published 2026-11-13 · https://inpherio.co.uk/blog/anthropic-api-compatible-open-models

Key points:
- POST /v1/messages accepts Anthropic's Messages format and translates it to and from the host's engine.
- Supported fields are model, messages, max_tokens, an optional system prompt and streaming.
- The Anthropic Python and TypeScript SDKs work by setting base_url and using your key.
- For tool calling, JSON output and embeddings, use the OpenAI-compatible routes, which cover more of the surface.

APIs have converged on two shapes: OpenAI's chat completions and Anthropic's Messages. A lot of agents, internal tools and SDK wrappers were written against the Messages format. If that's your code, you can point it at open models without a rewrite. Here's what an Anthropic API compatible endpoint for open models gives you and where its edges are.

## How it works

`POST /v1/messages` accepts an Anthropic-format request, translates it into what the host's engine understands (Ollama, vLLM, llama.cpp and the rest), runs it, and translates the reply back into Anthropic's response shape. The same API key also works on the OpenAI routes and on Ollama's `/api/chat`, so you can mix formats in one project.

## Using the Anthropic SDK

Python:

```python
import anthropic
client = anthropic.Anthropic(base_url="https://inpherio.co.uk", api_key="YOUR_KEY")
msg = client.messages.create(
    model="qwen3:14b",
    max_tokens=400,
    system="You are a concise assistant.",
    messages=[{"role": "user", "content": "Give me three names for a hiking app."}],
)
print(msg.content[0].text)
```

TypeScript works the same way: pass `baseURL` and `apiKey` when you create the client. Use any model ID from `GET /v1/models` or the [marketplace](/marketplace).

Streaming:

```python
with client.messages.stream(model="qwen3:14b", max_tokens=400,
        messages=[{"role": "user", "content": "Write a haiku about GPUs."}]) as s:
    for text in s.text_stream:
        print(text, end="")
```

(Live on Inpherio: https://inpherio.co.uk/models/qwen3:14b)

## What's supported, exactly

| Field | Supported |
|---|---|
| `model` | Yes: any live open model |
| `messages` (user and assistant turns) | Yes |
| `max_tokens` | Yes |
| `system` | Yes |
| `stream` | Yes, Anthropic-style events |

That covers most chat, summarising, drafting and Q&A code. The [API reference](/api-reference) lists the route and its errors.

## When to use the OpenAI format instead

The OpenAI-compatible routes cover more of the surface, so use them for:

- **Tool or function calling**, and agent frameworks that depend on it.
- **Structured output**, such as JSON schema replies.
- **Embeddings** (`/v1/embeddings`), **text-to-speech** (`/v1/audio/speech`) and **transcription** (`/v1/audio/transcriptions`).

Most agent frameworks can talk to either format, so a common pattern is Anthropic format for plain chat in existing code, and OpenAI format for anything new. Our guide to [switching from the OpenAI API](/blog/openai-api-alternative-open-models) covers that side.

## Choosing an open model for Messages-style code

Code written for Anthropic models tends to use long system prompts and expect careful instruction following. Good open choices:

- **Qwen3 14B and Qwen3 30B-A3B** for instruction following and multilingual text.
- **gpt-oss 20B** for reasoning-heavy prompts.
- **Gemma 3 12B** for well-behaved general chat.

Check the context window each host actually serves on the model's page; it can be lower than the model's maximum. Our [best LLM right now](/blog/best-llm-right-now-what-s-trending-what-runs-what-we-d-pick-nov-2026) round-up is a fuller shortlist.

(Live on Inpherio: https://inpherio.co.uk/models/gpt-oss-20b-Q4_K_M)

## Translating an existing Anthropic integration

Most Anthropic integrations need three changes:

1. **Base URL.** Point the client at `https://inpherio.co.uk` (the SDK adds `/v1/messages`).
2. **Key.** Use an API key from the dashboard instead of an Anthropic key.
3. **Model name.** Replace the Claude model ID with an open model ID from `GET /v1/models`.

Everything else in a plain chat call, the messages array, the system prompt, `max_tokens` and streaming, stays as it is. If your code reads `msg.content[0].text` or iterates `text_stream`, it keeps working.

Things to check while you test:

- **Long system prompts.** Open models handle them, but they reward clear structure: headings, numbered rules and an example of the output you want.
- **Output length.** Set `max_tokens` deliberately; some open models write longer answers than you're used to.
- **Refusals and tone.** Different models draw lines in different places. Run your edge-case prompts, not just the happy path.
- **Context window.** The model page shows what each host actually serves. Trim conversation history if you're near the limit.

## A side-by-side test harness

The quickest way to decide is to run the same prompts through two clients and compare:

```python
import anthropic
a = anthropic.Anthropic(base_url="https://inpherio.co.uk", api_key="YOUR_KEY")
for model in ["qwen3:14b", "gemma3:12b", "gpt-oss-20b-Q4_K_M"]:
    for prompt in test_prompts:
        out = a.messages.create(model=model, max_tokens=500,
                messages=[{"role": "user", "content": prompt}])
        record(model, prompt, out.content[0].text)
```

Score the outputs blind if you can, with a simple rubric: correct, complete, right length, right tone. You'll usually find one open model that's good enough for most of your prompts, and a handful of prompts that still need something bigger.

## Common errors and what they mean

| Status | Meaning | What to do |
|---|---|---|
| 400 | Malformed request | Check the body matches the Messages shape |
| 401 | Bad key | Use a key from the dashboard, not an Anthropic key |
| 402 | Balance can't cover the prompt | Top up; nothing ran and nothing was charged |
| 404 | No host serving that model right now | Pick another model from `GET /v1/models` |
| 429 | Rate limit, spend cap or key budget reached | Wait for `Retry-After`; check your caps |
| 502 / 503 | Every candidate failed or is at capacity | Safe to retry with backoff |

A 404 is the one that surprises people coming from a single provider: on a marketplace, a model is available while a host serves it. If you depend on one model, keep a second choice in your config, or rent a machine for guaranteed capacity.

## Testing without a card

You can try the Messages route on [free models](/free-models) before adding credit: create an account, verify your email, make a key and point the Anthropic SDK at it. Free calls are limited to 50 an hour per model and 100 a day, which is plenty for a first comparison. When a model looks promising, add £10 of credit and run your full test set on the larger models.

## Why use the Messages format at all

If you're starting fresh, the OpenAI format covers more features. The Messages route exists so code that already speaks Anthropic's format doesn't need a rewrite to try open models, and so mixed codebases can use one key for both styles.

## Pricing and limits

You pay the host's listed price per million input and output tokens, with nothing added; failed requests cost £0. Chat endpoints allow 60 requests a minute per key. Prepaid credit starts at £10, and [free models](/free-models) let you test without a card. One thing to know: prompts are processed on independent hosts' machines, so keep confidential data off the open marketplace, as the [security page](/security) explains.



If your codebase speaks Anthropic's format, the cheapest experiment you can run is changing one base URL and comparing answers on your own prompts.

## FAQ

**Can I use the Anthropic SDK with open models?** Yes. Set the SDK's base URL to https://inpherio.co.uk and use your key; requests to /v1/messages are translated to the host's engine and the replies come back in Anthropic's format.
**Does it support streaming?** Yes. Set stream to true and you get Anthropic-style server-sent events.
**Does it support tool use?** The Messages route documents model, messages, max_tokens, system and stream. If you need tool calling or structured output, use /v1/chat/completions in OpenAI format.
**Is this Claude?** No. It's the Anthropic request and response format in front of open models such as Qwen, Gemma, Llama and gpt-oss, run by independent hosts.
