Basic

Use Ollama's OpenAI-compatible /v1/responses endpoint with an Agent.

Basic example using Ollama with the OpenAI Responses API.

Use Ollama server v0.13.3 or later, independently of the installed Python SDK version. Follow the standalone setup below: this program uses gpt-oss:20b, despite the older llama3.1:8b pull command in the preserved source comment.

basic.py
"""Basic example using Ollama with the OpenAI Responses API.

This uses Ollama's OpenAI-compatible /v1/responses endpoint, which was added
in Ollama v0.13.3. It provides an alternative to the native Ollama API.

Requirements:
- Ollama v0.13.3 or later running locally
- Run: ollama pull llama3.1:8b
"""

import asyncio

from agno.agent import Agent
from agno.models.ollama import OllamaResponses

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------

agent = Agent(
    model=OllamaResponses(id="gpt-oss:20b"),
    markdown=True,
)

# Print the response in the terminal

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    # --- Sync ---
    agent.print_response("Share a 2 sentence horror story")

    # --- Sync + Streaming ---
    agent.print_response("Write a short poem about the moon", stream=True)

    # --- Async ---
    asyncio.run(agent.aprint_response("Share a 2 sentence horror story"))

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U agno ollama openai

Select the local Ollama server

In the shell used for the pull commands and Python example, clear a previous cloud key and point native clients and embeddings at your local server:

unset OLLAMA_API_KEY
export OLLAMA_HOST="http://localhost:11434"

Without this reset, OLLAMA_API_KEY makes Agno's default Ollama model route to https://ollama.com even when OLLAMA_HOST points locally. Keep a local Ollama server running for the following steps.

Prepare Ollama

Install and start Ollama server v0.13.3 or later, then pull the model used by this example:

ollama pull gpt-oss:20b

Run the example

Save the code above as basic.py, then run:

python basic.py

Full source: cookbook/90_models/ollama/responses/basic.py