Skip to main content

Genkit Ollama Plugin

This Genkit plugin connects Python apps to locally running Ollama models for chat, streaming, tool calling, multimodal prompts, and embeddings.

Installation

uv add genkit genkit-ollama

Install Ollama from ollama.com/download, then start the local server:

ollama serve

Ollama serves http://127.0.0.1:11434 by default. Pull the models your app will use before running Genkit:

ollama pull llama3.2
ollama pull nomic-embed-text

Usage

from genkit import Genkit
from genkit_ollama import EmbeddingDefinition, ModelDefinition, Ollama

ai = Genkit(
    plugins=[
        Ollama(
            models=[ModelDefinition(name='llama3.2')],
            embedders=[EmbeddingDefinition(name='nomic-embed-text')],
        )
    ],
    model='ollama/llama3.2',
)

response = await ai.generate(prompt='Write a haiku about local models.')
print(response.text)

embeddings = await ai.embed(embedder='ollama/nomic-embed-text', content='local inference')
print(len(embeddings[0].embedding))

These snippets assume an async context (await inside an async def); pasting them at module top level raises SyntaxError: 'await' outside function. See the runnable sample for a complete async def main() plus ai.run_main(...) entry point.

Streaming

stream_response = ai.generate_stream(prompt='Stream a haiku about Ollama.')
async for chunk in stream_response.stream:
    print(chunk.text, end='', flush=True)
final = await stream_response.response

Tool calling

from pydantic import BaseModel, Field


class WeatherInput(BaseModel):
    city: str = Field(description='City to look up')


@ai.tool()
async def current_weather(input: WeatherInput) -> str:
    return f'{input.city} is 18°C and partly cloudy.'


response = await ai.generate(
    prompt='What is the weather in London?',
    tools=['current_weather'],
)
print(response.text)

Ollama tool inputs are object schemas, so wrap primitive inputs in a Pydantic model as above. When a tool's schema declares properties but omits an explicit type, the plugin infers an object schema rather than dropping the tool.

JSON / schema-constrained output

from pydantic import BaseModel


class Haiku(BaseModel):
    line_one: str
    line_two: str
    line_three: str


response = await ai.generate(
    prompt='Write a haiku about local models.',
    output_schema=Haiku,
)
print(response.output)

Ollama-specific config (OllamaConfig)

OllamaConfig extends the common Genkit ModelConfig with Ollama-only knobs (think, keep_alive, num_ctx, min_p, seed, num_predict):

from genkit_ollama import OllamaConfig

# Reasoning model with a 32k context window kept warm for an hour
response = await ai.generate(
    model='ollama/deepseek-r1',
    prompt='Plan a small REST API.',
    config=OllamaConfig(
        think=True,
        num_ctx=32_000,
        keep_alive='1h',
        temperature=0.2,
    ),
)

Remote server, headers, and timeouts

Ollama(server_address='http://ollama.example.com:11434')

# Static headers
Ollama(request_headers={'Authorization': 'Bearer <token>'})

# Async-resolved headers, re-evaluated per request (e.g. minting a short-lived token)
from genkit_ollama import RequestHeaderParams


async def auth_headers(params: RequestHeaderParams) -> dict[str, str]:
    return {'Authorization': f'Bearer {await mint_token(params.server_address)}'}


Ollama(request_headers=auth_headers, timeout=60.0)

Callable headers are re-evaluated on every request, so short-lived tokens refresh automatically. A static dict is applied once to a cached client.

Vision models

from genkit_ollama import ModelDefinition, Ollama, OllamaSupports

Ollama(models=[ModelDefinition(name='llava', supports=OllamaSupports(media=True))])

Media support is opt-in per model to avoid advertising a capability the underlying model does not actually have.

Troubleshooting

If the plugin can't reach the server it raises OllamaConnectionError with the URL it tried. Start the daemon (ollama serve) or set server_address to a reachable host.

Sample

See py/samples/ollama-sample for a runnable sample covering chat, streaming, tool calling, and embeddings with a local Ollama server.

Notes

Ollama is open-source software under the MIT License. Individual models pulled through Ollama have their own licenses; review model cards before production use. Models run locally on your hardware by default — no data leaves the machine unless you point the plugin at a remote Ollama server.

Acknowledgements

Thanks to the community contributors who built and maintained the original community version of this plugin.

License

Apache-2.0

Release files for genkit-ollama 0.10.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for genkit-ollama 0.10.0
File Size Uploaded
genkit_ollama-0.10.0.tar.gz 41.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for genkit-ollama 0.10.0
File Interpreter ABI Platform
genkit_ollama-0.10.0-py3-none-any.whl Python 3 none any Details

Total release size: 70.4 kB

Release files / genkit_ollama-0.10.0.tar.gz

Download URL genkit_ollama-0.10.0.tar.gz
Size 41.5 kB
Tags Source
SHA-256 checksum
How to use checksums
6f3ebbdc6d072f4c251512bf4f67a20e375088cb2b8df1ca53332f4fcb7dd09b
BLAKE2b-256 checksum
How to use checksums
6b75608612695edfa7142cde88b87e10175dbcb1c8e16727a5f2355a14a568b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.

Transparency log

Release files / genkit_ollama-0.10.0-py3-none-any.whl

Download URL genkit_ollama-0.10.0-py3-none-any.whl
Size 28.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
65ce712dd242854ea0855e69102049d9dcc1ddeecd6baeda4771d3c8f2ca66a0
BLAKE2b-256 checksum
How to use checksums
7113f12e707150b0eb43ddf40583a264e21e10aaffc3eb23df2d6aaa9440f33d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.

Transparency log

Release history Release notifications | RSS feed

0.12.0

2 release files

This release

0.10.0 This release

2 release files

0.9.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page