skip to content

Pointing an Anthropic-SDK coding tool at a local Ollama 0.35 server, what do you configure, and which Messages API features stop working?

level: middleimportance: nice to knowfreq 5%

answer

  1. same port, a different base
  2. a token nobody checks
  3. the not-supported table
  4. token counting and prompt caching
  5. context still set server-side

basics

~10 s

Set the base URL to http://localhost:11434 with a placeholder token and a local model name. Ollama's /v1/messages handles messages, streaming, tools and thinking, but not tool_choice, count_tokens, prompt caching, batches, PDFs or image URLs.

solid answer

~40 s

Ollama 0.35.0 serves an Anthropic-style `/v1/messages` on its normal port, so a tool built on the Anthropic SDK needs `ANTHROPIC_BASE_URL=http://localhost:11434` (the bare host; the SDK adds `/v1/messages`) and a placeholder such as `ANTHROPIC_AUTH_TOKEN=ollama`, which the local server does not validate. The `model` is a local Ollama name, or one copied to the name the tool expects with `ollama cp`. Supported: text and content blocks, system prompts, multi-turn, streaming events, `tools` with `tool_use`/`tool_result`, `thinking`, base64 images, `top_k` and `stop_sequences`. Not supported: `/v1/messages/count_tokens`, `tool_choice`, `metadata`, `cache_control` prompt caching, the Batches API, citations and PDF `document` blocks; image URLs fail, `budget_tokens` is accepted but not enforced, and token counts are approximations. The context window still has to be raised server-side.

go deeper

for a junior

Recall the setup: base URL http://localhost:11434 without /v1, a placeholder token, and a local model name that has been pulled.

for a middle

Explain what the route supports — content blocks, streaming, tools, thinking — and what is missing: count_tokens, tool_choice, prompt caching, batches, PDFs and image URLs.

for a senior

Anticipate how a coding agent degrades locally: no prompt caching, approximate usage, ignored tool_choice, and a context that must be raised server-side before long sessions.

for a principal

Weigh running a hosted-API agent on local models for privacy or cost against the features lost, and decide which workflows the team keeps on the hosted service.

## The route and how a client reaches it Besides its native `/api` routes and the OpenAI-style `/v1` routes, Ollama 0.35.0 serves an **Anthropic-style `POST /v1/messages`** on the same `11434` port. Tools written against the Anthropic SDK, coding agents especially, can then run on a local model. Three settings make the connection: 1. **Base URL** `http://localhost:11434`. Unlike the OpenAI client's base, the documented value carries **no `/v1`**: the Anthropic SDK adds `/v1/messages` itself. 2. **A placeholder credential.** The docs set `ANTHROPIC_AUTH_TOKEN=ollama` and mark it "required but ignored"; the local server does not validate API keys. Ollama's hosted endpoint at `ollama.com/v1/messages` is different: it requires a real bearer token and does not accept `x-api-key` alone. 3. **A local model name** in `model`, such as `qwen3-coder`, pulled beforehand. A tool that insists on an Anthropic model name can be given one with `ollama cp qwen3-coder claude-3-5-sonnet`. For some tools Ollama does this wiring itself: `ollama launch claude` configures and starts Claude Code against Ollama models, and `--model` picks which one. Thinking control maps as well: `thinking.type` set to `enabled` or `disabled` acts as an explicit on/off switch, and `/api/show` reports which effort values a given model accepts. ## What carries over | Supported on Ollama's `/v1/messages` | Notes | |---|---| | `messages` with text or content blocks | including `tool_use`, `tool_result` and `thinking` blocks | | `system` | a string or an array | | `stream` | `message_start`, `content_block_delta` (text, `input_json_delta`, `thinking_delta`), `message_stop`, `ping` | | `tools` | function calling and tool results | | `thinking`, `output_config.effort` | `enabled` / `disabled`; named efforts are model-defined | | `temperature`, `top_p`, `top_k`, `stop_sequences`, `max_tokens` | sampling and limits | | images | base64 only | Responses carry `id`, `content` blocks, `stop_reason` (`end_turn`, `max_tokens`, `tool_use`) and `usage` with `input_tokens` and `output_tokens`. ## What stops working - **`/v1/messages/count_tokens`**: not supported, and the server on port 11434 registers no such route, so a tool that budgets its prompt through it must estimate instead. - **`tool_choice`**: not supported, so the model decides whether to call a tool. In 0.35.0 the field is parsed and then left unused, so sending it causes no error. - **`metadata`**: not supported. - **Prompt caching**: `cache_control` blocks are not supported, so a long system prompt is not cached the way the hosted API would cache it. - **The Batches API, citations and PDF `document` blocks**: not supported. - **Image URLs**: only base64 images work. - **Thinking budgets**: `budget_tokens` is accepted but not enforced. - **Token counts**: `usage` numbers are approximations from the local model's tokenizer. The pattern matches the OpenAI-style routes: several unsupported fields are accepted and ignored, so a request succeeds while behaving differently. The Messages contract itself (required `max_tokens`, block ordering, stop reasons) is the hosted API's subject; what belongs to Ollama is this list of gaps. ## The setting the API cannot reach Coding agents send long prompts: tool definitions, file contents, history. Ollama's documentation recommends a context of **at least 64000 tokens** for agents and coding tools, yet the Anthropic request, like the OpenAI one, has no field for the model's context size, and the server's default depends on the machine. Set it on the server before blaming the tool: ```bash OLLAMA_CONTEXT_LENGTH=64000 ollama serve ``` or build a model whose Modelfile sets `PARAMETER num_ctx`. How large a context a given GPU can hold is the offload material's question. Without one of these, a long agent session is trimmed from its oldest messages to fit, and the tool appears to forget what it was told. ## Checklist before handing the tool to a team - Base URL without `/v1`, a placeholder token, the model pulled. - Context raised server-side, then confirmed in the `CONTEXT` column of `ollama ps`. - No prompt caching and no token-counting route: turn off tool features that depend on them, where the tool allows it. - The local API is unauthenticated: keep the default loopback bind unless something in front of it checks credentials. - Pick a model that does tool calling well; the compatibility page suggests `qwen3-coder` for coding and `gpt-oss:20b` for general work, and a model without tool support makes tool requests fail outright.

  • The agent copes with short tasks but forgets its instructions in long sessions — what do you check first?
    The context Ollama allocated, shown in the `CONTEXT` column of `ollama ps`. The Messages request cannot set it, so a long history is trimmed from its oldest messages to fit. Raise it with `OLLAMA_CONTEXT_LENGTH` or a Modelfile `PARAMETER num_ctx`; the docs recommend at least 64000 tokens for coding tools.
  • Why can the tool's own token accounting disagree with what the local model actually processed?
    Ollama's server offers no `/v1/messages/count_tokens` route, so the tool must estimate, and the `usage` counts Ollama returns are approximations from the local tokenizer. Treat both as rough figures and keep a margin below the configured context.

  • The Anthropic base URL needs /v1 on the end, as the OpenAI one does.
  • Ollama's local server validates the Anthropic API key.
  • tool_choice forces a tool call on Ollama's /v1/messages.
  • cache_control blocks make Ollama cache the system prompt.
  • A field in the Messages request can raise Ollama's context window.

Assumes Ollama 0.35.0; the supported and unsupported Messages features are read from that release's Anthropic compatibility page and source.