Skip to main content
Connect Anthropic clients and tools such as Claude Code to Ollama. Ollama supports a subset of the Anthropic Messages API.

Direct cloud access

Set your API key in OLLAMA_API_KEY. No Ollama installation required.
Send a request with bearer authentication:
Read text blocks from content. The cloud endpoint requires Authorization: Bearer; it does not accept x-api-key alone. Compatible models support messages, streaming, and function calling. Tool-choice controls, deferred tools, and hosted web search are not fully supported.

Local server usage

These examples connect to your local Ollama server. Use ollama as the placeholder API key. To use cloud models through this server, sign in to Ollama.

Environment variables

To use Ollama with tools that expect the Anthropic API (like Claude Code), set these environment variables:

Simple /v1/messages example

basic.py

Streaming example

streaming.py

Tool calling example

tools.py

Using with Claude Code

See the Claude Code guide for Ollama Launch and direct cloud setup.

Endpoints

/v1/messages

Supported features

  • Messages
  • Streaming
  • System prompts
  • Multi-turn conversations
  • Vision (images)
  • Tools (function calling)
  • Tool results
  • Thinking/extended thinking

Supported request fields

  • model
  • max_tokens
  • messages
    • Text content
    • Image content (base64)
    • Array of content blocks
    • tool_use blocks
    • tool_result blocks
    • thinking blocks
  • system (string or array)
  • stream
  • temperature
  • top_p
  • top_k
  • stop_sequences
  • tools
  • thinking
  • output_config
    • effort (model-defined names)
  • tool_choice
  • metadata

Supported response fields

  • id
  • type
  • role
  • model
  • content (text, tool_use, thinking blocks)
  • stop_reason (end_turn, max_tokens, tool_use)
  • usage (input_tokens, output_tokens)

Streaming events

  • message_start
  • content_block_start
  • content_block_delta (text_delta, input_json_delta, thinking_delta)
  • content_block_stop
  • message_delta
  • message_stop
  • ping
  • error
Use /api/show to discover a model’s supported thinking values and default. thinking.type: "enabled" and "disabled" act as explicit on/off controls. When a model uses its metadata to resolve named levels, supported output_config.effort names are applied exactly and unsupported names resolve to the model default. Models without metadata keep the existing compatibility behavior, which trims and lowercases effort names and maps "xhigh" to "high".

Models

Ollama supports both local and cloud models.

Local models

Pull a local model before use:
Recommended local models:
  • qwen3-coder - Excellent for coding tasks
  • gpt-oss:20b - Strong general-purpose model

Cloud models

Browse the cloud model catalog. Through a signed-in Ollama server, use a cloud name such as gemma4:cloud without a separate pull. For direct cloud requests, use the hosted identifier, such as gemma4:31b.

Default model names on a local server

For tooling that relies on default Anthropic model names such as claude-3-5-sonnet, use ollama cp to copy an existing model name:
Afterwards, this new model name can be specified in the model field:

Differences from the Anthropic API

Behavior differences

  • 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

Not supported

The following Anthropic API features are not currently supported:

Partial support