Direct cloud access
Set your API key inOLLAMA_API_KEY. No Ollama installation required.
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. Useollama 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_useblocks -
tool_resultblocks -
thinkingblocks
- Text
-
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
/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:qwen3-coder- Excellent for coding tasksgpt-oss:20b- Strong general-purpose model
Cloud models
Browse the cloud model catalog. Through a signed-in Ollama server, use a cloud name such asgemma4: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 asclaude-3-5-sonnet, use ollama cp to copy an existing model name:
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-versionvalues older than2023-06-01. Use2023-06-01in requests. - Token counts are approximations based on the underlying model’s tokenizer

