Ollama OpenAI and Anthropic compatibility endpoints
Parent: Ollama core platform · Published reference · snapshot 2026-10-14 · skill ollama-expert/references/ollama-core-platform.md
↓ Facts as markdownall context files
Everything the scanned sources say about Ollama OpenAI and Anthropic compatibility endpoints: 73 source-anchored units across 6 sources, grouped by facet.
These notes link each claim to its source. Some citations identify archived research reports that are no longer hosted on this site. A published reference means the content is available; it does not certify independent review or accuracy.Read the editorial policy and follow the sources before relying on a claim.
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]
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]
- 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]
- 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]
- 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]
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]
- To invoke Ollama’s OpenAI compatible API endpoint, use the same OpenAI format and change the hostname to http://localhost:11434: [source]
Examples and snippets
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]
- 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]
- 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]
- 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]
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]
- 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]
- 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]
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]
- 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]
- 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]
- 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]
- 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]
- ```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]
- 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]
- <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]
- client = anthropic.Anthropic( base_url='http://localhost:11434', api_key='ollama', # required but ignored ) [source]
- const anthropic = new Anthropic({ baseURL: "http://localhost:11434", apiKey: "ollama", // required but ignored }); [source]
- ```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]
- 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]
- client = OpenAI( base_url='http://localhost:11434/v1/', api_key='ollama', # required but ignored ) [source]
- const openai = new OpenAI({ baseURL: "http://localhost:11434/v1/", apiKey: "ollama", // required but ignored }); [source]
- | 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]
- <CodeGroup> ```python basic.py theme={"system"} import anthropic [source]
- ```javascript basic.js theme={"system"} import Anthropic from "@anthropic-ai/sdk"; [source]
- * 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]
- <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]
- message = client.messages.create( model='qwen3-coder', max_tokens=1024, messages=[ {'role': 'user', 'content': 'Hello, how are you?'} ] ) print(message.content[0].text) ``` [source]
- const message = await anthropic.messages.create({ model: "qwen3-coder", max_tokens: 1024, messages: [{ role: "user", content: "Hello, how are you?" }], }); [source]
- console.log(message.content[0].text); ``` [source]
- <CodeGroup> ```python basic.py theme={"system"} from openai import OpenAI [source]
- ```javascript basic.js theme={"system"} import OpenAI from "openai"; [source]
- console.log(chatCompletion.choices[0].message.content); ``` [source]
- <CodeGroup> ```python responses.py theme={"system"} from openai import OpenAI [source]
- ```javascript responses.js theme={"system"} import OpenAI from "openai"; [source]
- <CodeGroup> ```python vision.py theme={"system"} from openai import OpenAI [source]
- ```javascript vision.js theme={"system"} import OpenAI from "openai"; [source]
- 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]
- Connect Anthropic clients and tools such as Claude Code to Ollama. Ollama supports a subset of the Anthropic Messages API. [source]
- 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]
- Read the answer from `choices[0].message.content`. See [OpenAI compatibility](/api/openai-compatibility) for client setup and supported features. </Tab> [source]
- /v1/messages/count_tokensToken counting endpoint [source]
- The Anthropic client appends `/v1/messages` to its base URL. [source]
- Claude Code with Anthropic API compatibility [source]
- 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]
- Existing applications using the Anthropic SDK can connect to Ollama by changing the base URL. See the Anthropic compatibility documentation for details. [source]
- For a complete list of supported features, see the Anthropic compatibility documentation. [source]
- GitHub issues are welcome! For more information, see the OpenAI compatibility docs. [source]
- llama-server as an OpenAI-compatible API in Docker, tested with the official SDKs [source]
- * 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]
- 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]
- <Card title="Build an application" icon="code" href="/quickstart#build-an-application"> Call cloud models with Ollama, OpenAI, or Anthropic APIs. </Card> </CardGroup> [source]
- Ollama connects Claude Code to local and cloud models through its Anthropic-compatible API. [source]
- 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]
- Copilot CLI connects to Ollama using the OpenAI-compatible API via environment variables. [source]
- 3. Set the API base URL to the Ollama OpenAI-compatible endpoint: [source]
- Pool connects to Ollama using the OpenAI-compatible API via environment variables. [source]
- 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]
- 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]
- OpenAI and Anthropic compatibility each cover a subset of the original API. See [Cloud](/cloud) for models and usage limits. </Tab> [source]
- Read text blocks from `content`. See [Anthropic compatibility](/api/anthropic-compatibility) for client setup and supported features. </Tab> </Tabs> </Tab> </Tabs> [source]
- 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]
- /v1/chat/completions with vision example [source]
- 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]
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
Children
- No children recorded.