Ollama Responses
Configure OllamaResponses, Agno's model class for Ollama's OpenAI-compatible Responses API.
Interact with Ollama models using the OpenAI Responses API. This uses Ollama's OpenAI-compatible /v1/responses endpoint, added in Ollama v0.13.3.
Requirements
- Ollama v0.13.3 or later
- For local usage: Ollama server running at
http://localhost:11434 - For Ollama Cloud: Set
OLLAMA_API_KEYenvironment variable
uv pip install -U agno openaiKey Features
- Dual Deployment: Run locally for privacy or use Ollama Cloud for scalability
- Auto-configuration: When using an API key, the host automatically defaults to Ollama Cloud
- Stateless API: Each request is independent (no
previous_response_idchaining)
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
id | str | "gpt-oss:20b" | The ID of the Ollama model to use |
name | str | "OllamaResponses" | The name of the model |
provider | str | "Ollama" | The provider of the model |
host | Optional[str] | None | The Ollama server host (defaults to http://localhost:11434) |
api_key | Optional[str] | None | The API key for Ollama Cloud (defaults to OLLAMA_API_KEY env var, not required for local) |
OllamaResponses extends OpenResponses and inherits its constructor parameters. Use host to select the endpoint: inherited base_url is currently ignored. Without an explicit host, setting OLLAMA_API_KEY selects Ollama Cloud.
Usage
Local Usage
With the local Ollama server running, download the model first:
ollama pull gpt-oss:20bfrom agno.agent import Agent
from agno.models.ollama import OllamaResponses
agent = Agent(
model=OllamaResponses(id="gpt-oss:20b", host="http://localhost:11434"),
markdown=True,
)
agent.print_response("Share a 2 sentence horror story")Ollama Cloud
Set the OLLAMA_API_KEY environment variable:
export OLLAMA_API_KEY=your-api-keyfrom agno.agent import Agent
from agno.models.ollama import OllamaResponses
agent = Agent(
model=OllamaResponses(id="gpt-oss:20b"),
markdown=True,
)
agent.print_response("Share a 2 sentence horror story")Custom Host
from agno.agent import Agent
from agno.models.ollama import OllamaResponses
agent = Agent(
model=OllamaResponses(
id="gpt-oss:20b",
host="http://my-ollama-server:11434",
),
markdown=True,
)
agent.print_response("Hello!")Developer Resources
- Ollama Responses API Documentation
- Ollama (Chat Completion API)