<!-- llms-explorer concept facts · https://llms-explorer.com/tree/ollama-openai-and-anthropic-compatibility-endpoints/ · pack 2026-10-14 · ~5358 tokens -->

# Ollama OpenAI and Anthropic compatibility endpoints

> Everything the scanned sources say about Ollama OpenAI and Anthropic compatibility endpoints: 73 source-anchored units across 6 sources, grouped by facet.

Parent: [Ollama core platform](https://llms-explorer.com/tree/ollama-core-platform/) · 7 facets · 73 facts · page: https://llms-explorer.com/tree/ollama-openai-and-anthropic-compatibility-endpoints/

## Structure and components

- The OpenAI layer launched 2024-02-08 as 'initial experimental support' for chat completions only; embeddings, function calling, vision and logprobs were listed as future work and have since been added (except logprobs). — [source](https://ollama.com/blog/openai-compatibility)

## How it works

- Most likely your framework calls Ollama's OpenAI-compatible endpoint at /v1, which ignores num_ctx in the request body because it isn't on the allowlist of OpenAI parameters Ollama maps. Only the native /api/generate and /api/chat endpoints accept it. Set OLLAMA_CONTEXT_LENGTH on the server or bake num_ctx into a Modelfile, then confirm with the CONTEXT column in ollama ps. — [source](https://www.betterclaw.io/blog/ollama-context-window-truncates-agent-config)
- Chat completions does not support tool_choice, logit_bias, user or n per Ollama docs. A llama-stack project fix (PR #2047, Apr 2025) worked around Ollama still calling tools when tool_choice="none" by stripping tools from the request. — [source](https://docs.ollama.com/api/openai-compatibility)
- Most agent frameworks talk to Ollama over the OpenAI-compatible endpoint, because that's the thing every SDK already speaks. So you set num_ctx in your framework config, the framework passes it into an OpenAI-shaped request, and Ollama drops it on the floor. Your window stays at 4096 and nothing anywhere reports a problem. — [source](https://www.betterclaw.io/blog/ollama-context-window-truncates-agent-config)
- Server-wide, OLLAMA_CONTEXT_LENGTH. The default for every request that doesn't carry its own. This is the one to use for agents, because it survives the OpenAI-compatible endpoint problem above. — [source](https://www.betterclaw.io/blog/ollama-context-window-truncates-agent-config)

## How-to and procedures

- Use the API key in the `Authorization: Bearer` header. This also applies to the hosted Anthropic-compatible `/v1/messages` endpoint; `x-api-key` alone is not supported. — [source](https://docs.ollama.com/api/authentication#api-keys)
- To invoke Ollama’s OpenAI compatible API endpoint, use the same OpenAI format and change the hostname to http://localhost:11434: — [source](https://ollama.com/blog/openai-compatibility)

## Examples and snippets

- ```shell theme={"system"} — `curl http://localhost:11434/v1/chat/completions \` … — [source](https://docs.ollama.com/api/openai-compatibility#default-model-names-on-a-local-server)
- ```shell theme={"system"} — `curl http://localhost:11434/v1/chat/completions \` … — [source](https://docs.ollama.com/api/openai-compatibility#setting-the-local-context-size)
- ```json theme={"system"} — `"$schema": "https://opencode.ai/config.json",` … — [source](https://docs.ollama.com/integrations/opencode#manual-setup)

## Measurements and reference values

- ```shell vision.sh theme={"system"} curl -X POST http://localhost:11434/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{ "model": "qwen3-vl:8b", "messages": [{ "role": "user", "content": [{"type": "text", "text": "What is this an image of?"}, {"type": "image_url", "image_url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAG0AAABmCAYAAADBPx+VAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAA3VSURBVHgB7Z27r0zdG8fX743i1bi1ikMoFMQloXRpKFFIqI7LH4BEQ+NWIkjQuSWCRIEoULk0gsK1kCBI0IhrQVT7tz/7zZo888yz1r7MnDl7z5xvsjkzs2fP3uu71nNfa7lkAsm7d++Sffv2JbNmzUqcc8m0adOSzZs3Z+ — [source](https://docs.ollama.com/api/openai-compatibility#v1-chat-completions-with-vision-example)
- curl -X POST http://localhost:11434/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{ "model": "qwen3-vl:8b", "messages": [{ "role": "user", "content": [{"type": "text", "text": "What is this an image of?"}, {"type": "image_url", "image_url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAG0AAABmCAYAAADBPx+VAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAA3VSURBVHgB7Z27r0zdG8fX743i1bi1ikMoFMQloXRpKFFIqI7LH4BEQ+NWIkjQuSWCRIEoULk0gsK1kCBI0IhrQVT7tz/7zZo888yz1r7MnDl7z5xvsjkzs2fP3uu71nNfa7lkAsm7d++Sffv2JbNmzUqcc8m0adOSzZs3Z+/XES4ZckAWJEGWPiCxjsQNLWmQsWjRIpMsea — [source](https://docs.ollama.com/api/openai-compatibility)
- response = client.chat.completions.create( model='qwen3-vl:8b', messages=[ { 'role': 'user', 'content': [ {'type': 'text', 'text': "What's in this image?"}, { 'type': 'image_url', 'image_url': 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAG0AAABmCAYAAADBPx+VAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAA3VSURBVHgB7Z27r0zdG8fX743i1bi1ikMoFMQloXRpKFFIqI7LH4BEQ+NWIkjQuSWCRIEoULk0gsK1kCBI0IhrQVT7tz/7zZo888yz1r7MnDl7z5xvsjkzs2fP3uu71nNfa7lkAsm7d++Sffv2JbNmzUqcc8m0adOSzZs3Z+/XES4ZckAWJEGWPiCxjsQNLWmQsWjRIpMseaxcuTKpG/7HP27I8P79e7dq1ars/yL4/v27S0ejqwv+cUOGEGGpKHR37tzJCEpHV9tn — [source](https://docs.ollama.com/api/openai-compatibility#v1-chat-completions-with-vision-example)
- const response = await openai.chat.completions.create({ model: "qwen3-vl:8b", messages: [ { role: "user", content: [ { type: "text", text: "What's in this image?" }, { type: "image_url", image_url: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAG0AAABmCAYAAADBPx+VAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAA3VSURBVHgB7Z27r0zdG8fX743i1bi1ikMoFMQloXRpKFFIqI7LH4BEQ+NWIkjQuSWCRIEoULk0gsK1kCBI0IhrQVT7tz/7zZo888yz1r7MnDl7z5xvsjkzs2fP3uu71nNfa7lkAsm7d++Sffv2JbNmzUqcc8m0adOSzZs3Z+/XES4ZckAWJEGWPiCxjsQNLWmQsWjRIpMseaxcuTKpG/7HP27I8P79e7dq1ars/yL4/v27S0ejqwv+cUOGEGGpKHR37tzJCEp — [source](https://docs.ollama.com/api/openai-compatibility#v1-chat-completions-with-vision-example)

## Problems, failure modes and limitations

- | Feature | Description | | - | - | | `/v1/messages/count_tokens` | Token counting endpoint | | `tool_choice` | Forcing specific tool use or disabling tools | | `metadata` | Request metadata (user\_id) | | Prompt caching | `cache_control` blocks for caching prefixes | | Batches API | `/v1/messages/batches` for async batch processing | | Citations | `citations` content blocks | | PDF support | `document` content blocks with PDF files | | Server-sent errors | `error` events during streaming (errors return HTTP status) | — [source](https://docs.ollama.com/api/anthropic-compatibility#not-supported)
- Anthropic-compatible proxies can fail on Claude Code's experimental beta parameters (400 errors); agentgateway documents CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 as the workaround. Whether this applies to Ollama is untested here. The hosted Ollama endpoint rejects anthropic-version older than 2023-06-01. — [source](https://agentgateway.dev/docs/standalone/latest/integrations/llm/clients/claude-code/)
- This fix detects failure; it does not solve the underlying cause. A timeout, proxy disconnection, model loading problem, or user cancellation may need different handling. A completion marker also does not prove factual correctness or that the model satisfied the request. Tool-call responses and OpenAI-compatible event streams need their own readers. — [source](https://kingy.ai/?p=930586)

## Facts and statements

- Ollama exposes two API surfaces. The native one (/api/generate, /api/chat) accepts an options object containing num_ctx. The OpenAI-compatible one (/v1/chat/completions) does not. Ollama maps a fixed allowlist of OpenAI sampling parameters to model options, and num_ctx isn't on it, so the endpoint silently ignores it whether you send it nested in options or top-level. This is tracked in Ollama issue #11409 and still reproduces on current builds. — [source](https://www.betterclaw.io/blog/ollama-context-window-truncates-agent-config)
- Clients wanting OpenAI model names can alias a local model with `ollama cp llama3.2 gpt-3.5-turbo`. The OpenAI API has no context-size field; set num_ctx via a Modelfile PARAMETER and `ollama create`. — [source](https://docs.ollama.com/api/openai-compatibility)
- Anthropic Messages compatibility is served at /v1/messages (local http://localhost:11434, cloud https://ollama.com). Clients set ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN=ollama (ignored locally). It requires Ollama v0.14.0+ (blog dated 2026-01-16). — [source](https://docs.ollama.com/api/anthropic-compatibility)
- OpenAI-compatible base URL is http://localhost:11434/v1/ locally and https://ollama.com/v1 for cloud (OLLAMA_API_KEY). Locally the client must send some API key value, but Ollama ignores it. — [source](https://docs.ollama.com/api/openai-compatibility)
- Creating or deleting models requires a local Ollama server. [System One](/capabilities/decision) also requires a local server and is not yet available in Ollama's cloud. For supported API features, see [OpenAI compatibility](/api/openai-compatibility) and [Anthropic compatibility](/api/anthropic-compatibility). — [source](https://docs.ollama.com/api/introduction#base-urls)
- ```shell basic.sh theme={"system"} curl -X POST http://localhost:11434/v1/messages \ -H "Content-Type: application/json" \ -H "x-api-key: ollama" \ -H "anthropic-version: 2023-06-01" \ -d '{ "model": "qwen3-coder", "max_tokens": 1024, "messages": [{ "role": "user", "content": "Hello, how are you?" }] }' ``` </CodeGroup> — [source](https://docs.ollama.com/api/anthropic-compatibility#simple-v1-messages-example)
- curl http://localhost:11434/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{ "model": "llama2", "messages": [ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "Hello!" } ] }' — [source](https://ollama.com/blog/openai-compatibility)
- <Tab title="OpenAI Chat Completions"> ```shell theme={"system"} curl http://localhost:11434/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{ "model": "gemma4:e2b", "messages": [ { "role": "user", "content": "Say hello in one sentence." } ] }' ``` — [source](https://docs.ollama.com/quickstart#2-send-a-request)
- client = anthropic.Anthropic( base_url='http://localhost:11434', api_key='ollama', # required but ignored ) — [source](https://ollama.com/blog/claude)
- const anthropic = new Anthropic({ baseURL: "http://localhost:11434", apiKey: "ollama", // required but ignored }); — [source](https://docs.ollama.com/api/anthropic-compatibility)
- ```shell responses.sh theme={"system"} curl -X POST http://localhost:11434/v1/responses \ -H "Content-Type: application/json" \ -d '{ "model": "qwen3:8b", "input": "Write a short poem about the color blue" }' ``` </CodeGroup> — [source](https://docs.ollama.com/api/openai-compatibility#simple-v1-responses-example)
- You can also use [OpenAI](/api/openai-compatibility) or [Anthropic](/api/anthropic-compatibility) clients. Each supports a subset of the original API. No Ollama installation is required. — [source](https://docs.ollama.com/cloud#api-key)
- client = OpenAI( base_url='http://localhost:11434/v1/', api_key='ollama', # required but ignored ) — [source](https://docs.ollama.com/api/openai-compatibility)
- const openai = new OpenAI({ baseURL: "http://localhost:11434/v1/", apiKey: "ollama", // required but ignored }); — [source](https://docs.ollama.com/api/openai-compatibility)
- | API | Direct cloud access | Local Ollama server | | - | - | - | | Ollama | `https://ollama.com/api` | `http://localhost:11434/api` | | OpenAI compatibility | `https://ollama.com/v1` | `http://localhost:11434/v1` | | Anthropic client base URL | `https://ollama.com` | `http://localhost:11434` | — [source](https://docs.ollama.com/api/introduction#base-urls)
- <CodeGroup> ```python basic.py theme={"system"} import anthropic — [source](https://docs.ollama.com/api/anthropic-compatibility#simple-v1-messages-example)
- ```javascript basic.js theme={"system"} import Anthropic from "@anthropic-ai/sdk"; — [source](https://docs.ollama.com/api/anthropic-compatibility#simple-v1-messages-example)
- * The local server does not validate API keys. Direct cloud inference requires a valid bearer token. * The hosted endpoint rejects `anthropic-version` values older than `2023-06-01`. Use `2023-06-01` in requests. * Token counts are approximations based on the underlying model's tokenizer — [source](https://docs.ollama.com/api/anthropic-compatibility#behavior-differences)
- <Tab title="OpenAI Chat Completions"> ```shell theme={"system"} curl https://ollama.com/v1/chat/completions \ -H "Authorization: Bearer $OLLAMA_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "gemma4:31b", "messages": [ { "role": "user", "content": "Say hello in one sentence." } ] }' ``` — [source](https://docs.ollama.com/quickstart#2-send-a-request)
- message = client.messages.create( model='qwen3-coder', max_tokens=1024, messages=[ {'role': 'user', 'content': 'Hello, how are you?'} ] ) print(message.content[0].text) ``` — [source](https://docs.ollama.com/api/anthropic-compatibility#simple-v1-messages-example)
- const message = await anthropic.messages.create({ model: "qwen3-coder", max_tokens: 1024, messages: [{ role: "user", content: "Hello, how are you?" }], }); — [source](https://docs.ollama.com/api/anthropic-compatibility#simple-v1-messages-example)
- console.log(message.content[0].text); ``` — [source](https://docs.ollama.com/api/anthropic-compatibility#simple-v1-messages-example)
- <CodeGroup> ```python basic.py theme={"system"} from openai import OpenAI — [source](https://docs.ollama.com/api/openai-compatibility#simple-v1-chat-completions-example)
- ```javascript basic.js theme={"system"} import OpenAI from "openai"; — [source](https://docs.ollama.com/api/openai-compatibility#simple-v1-chat-completions-example)
- console.log(chatCompletion.choices[0].message.content); ``` — [source](https://docs.ollama.com/api/openai-compatibility#simple-v1-chat-completions-example)
- <CodeGroup> ```python responses.py theme={"system"} from openai import OpenAI — [source](https://docs.ollama.com/api/openai-compatibility#simple-v1-responses-example)
- ```javascript responses.js theme={"system"} import OpenAI from "openai"; — [source](https://docs.ollama.com/api/openai-compatibility#simple-v1-responses-example)
- <CodeGroup> ```python vision.py theme={"system"} from openai import OpenAI — [source](https://docs.ollama.com/api/openai-compatibility#v1-chat-completions-with-vision-example)
- ```javascript vision.js theme={"system"} import OpenAI from "openai"; — [source](https://docs.ollama.com/api/openai-compatibility#v1-chat-completions-with-vision-example)
- Ollama v0.14.0 and later are now compatible with the Anthropic Messages API, making it possible to use tools like Claude Code with open-source models. — [source](https://ollama.com/blog/claude)
- Connect Anthropic clients and tools such as Claude Code to Ollama. Ollama supports a subset of the Anthropic Messages API. — [source](https://docs.ollama.com/api/anthropic-compatibility)
- Connect Anthropic clients and tools such as Claude Code to Ollama. Ollama supports a subset of the [Anthropic Messages API](https://platform.claude.com/docs/en/api/http/messages/create). — [source](https://docs.ollama.com/api/anthropic-compatibility)
- Read the answer from `choices[0].message.content`. See [OpenAI compatibility](/api/openai-compatibility) for client setup and supported features. </Tab> — [source](https://docs.ollama.com/quickstart#2-send-a-request)
- /v1/messages/count_tokensToken counting endpoint — [source](https://docs.ollama.com/api/anthropic-compatibility)
- The Anthropic client appends `/v1/messages` to its base URL. — [source](https://docs.ollama.com/api/introduction#base-urls)
- Claude Code with Anthropic API compatibility — [source](https://ollama.com/blog/claude)
- Claude Code is Anthropic’s agentic coding tool that lives in your terminal. With Anthropic API support, you can now use Claude Code with any Ollama model. — [source](https://ollama.com/blog/claude)
- Existing applications using the Anthropic SDK can connect to Ollama by changing the base URL. See the Anthropic compatibility documentation for details. — [source](https://ollama.com/blog/claude)
- For a complete list of supported features, see the Anthropic compatibility documentation. — [source](https://ollama.com/blog/claude)
- GitHub issues are welcome! For more information, see the OpenAI compatibility docs. — [source](https://ollama.com/blog/openai-compatibility)
- llama-server as an OpenAI-compatible API in Docker, tested with the official SDKs — [source](https://jacar.es/en/import-hugging-face-model-into-ollama/)
- * Define schemas with Pydantic (Python) or Zod (JavaScript) so they can be reused for validation. * Lower the temperature (e.g., set it to `0`) for more deterministic completions. * Structured outputs work through the OpenAI-compatible API via `response_format` — [source](https://docs.ollama.com/capabilities/structured-outputs#tips-for-reliable-structured-outputs)
- Ollama can be integrated into most of the tools available either through direct integration of Ollama's API, Python / JavaScript libraries, OpenAI compatible API, and MCP server integration. — [source](https://docs.ollama.com/capabilities/web-search#other-integrations)
- <Card title="Build an application" icon="code" href="/quickstart#build-an-application"> Call cloud models with Ollama, OpenAI, or Anthropic APIs. </Card> </CardGroup> — [source](https://docs.ollama.com/index)
- Ollama connects Claude Code to local and cloud models through its Anthropic-compatible API. — [source](https://docs.ollama.com/integrations/claude-code)
- Choose a [cloud model](https://ollama.com/search?c=cloud) that supports tools. Basic chat and file edits work with compatible models. Hosted WebSearch and advanced tool controls are not fully supported. See [Anthropic compatibility](/api/anthropic-compatibility). — [source](https://docs.ollama.com/integrations/claude-code#connect-directly-to-ollama-s-cloud)
- Copilot CLI connects to Ollama using the OpenAI-compatible API via environment variables. — [source](https://docs.ollama.com/integrations/copilot-cli#manual-setup)
- 3. Set the API base URL to the Ollama OpenAI-compatible endpoint: — [source](https://docs.ollama.com/integrations/hermes#connect-to-ollama)
- Pool connects to Ollama using the OpenAI-compatible API via environment variables. — [source](https://docs.ollama.com/integrations/pool#manual-setup)
- Responses requests are stateless: include conversation history in each request. `previous_response_id` and `conversation` aren't supported. See [Responses compatibility](/api/openai-compatibility#responses-api). </Tab> — [source](https://docs.ollama.com/quickstart#2-send-a-request)
- Read text blocks from `content`. Direct cloud requests use bearer authentication. See [Anthropic compatibility](/api/anthropic-compatibility) for client setup and supported features. </Tab> </Tabs> — [source](https://docs.ollama.com/quickstart#2-send-a-request)
- OpenAI and Anthropic compatibility each cover a subset of the original API. See [Cloud](/cloud) for models and usage limits. </Tab> — [source](https://docs.ollama.com/quickstart#2-send-a-request)
- Read text blocks from `content`. See [Anthropic compatibility](/api/anthropic-compatibility) for client setup and supported features. </Tab> </Tabs> </Tab> </Tabs> — [source](https://docs.ollama.com/quickstart#2-send-a-request)
- Choose a cloud model. The cloud API does not support stateful Responses, built-in web search through /v1/responses, or custom/freeform tool-call replay. — [source](https://docs.ollama.com/api/openai-compatibility)
- /v1/chat/completions with vision example — [source](https://docs.ollama.com/api/openai-compatibility)
- Choose a [cloud model](https://ollama.com/search?c=cloud). The cloud API does not support stateful Responses, built-in web search through `/v1/responses`, or custom/freeform tool-call replay. — [source](https://docs.ollama.com/api/openai-compatibility#direct-cloud-access)

## Related concepts

- MESSAGE — is a related of Ollama OpenAI and Anthropic compatibility endpoints
- SYSTEM — is a related of Ollama OpenAI and Anthropic compatibility endpoints
- /v1/chat/completions — is a part of Ollama OpenAI and Anthropic compatibility endpoints
- localhost:11434 — is a part of Ollama OpenAI and Anthropic compatibility endpoints
- /v1/messages — is a part of Ollama OpenAI and Anthropic compatibility endpoints
- /v1/responses — is a part of Ollama OpenAI and Anthropic compatibility endpoints
- num_ctx — is a part of Ollama OpenAI and Anthropic compatibility endpoints
- PARAMETER — is a part of Ollama OpenAI and Anthropic compatibility endpoints
- REQUIRES — is a related of Ollama OpenAI and Anthropic compatibility endpoints
- /api/generate — is a part of Ollama OpenAI and Anthropic compatibility endpoints
- /api/chat — is a part of Ollama OpenAI and Anthropic compatibility endpoints
- tool_choice — is a part of Ollama OpenAI and Anthropic compatibility endpoints
- stream — is a part of Ollama OpenAI and Anthropic compatibility endpoints
- ollama create — is a part of Ollama OpenAI and Anthropic compatibility endpoints
- tool_calls — is a part of Ollama OpenAI and Anthropic compatibility endpoints
