Official Python client for Ollama — the local LLM runtime. Wraps the Ollama REST API with native Python types. Requires Ollama to be installed and running locally (or pointed at https://ollama.com for cloud models). Not an inference provider — it's a runtime client.
pip install ollamaVerified import paths — ran on the pinned version, not inferred.
Basic chat with a locally running model
Install the Ollama runtime separately from https://ollama.com/download, then run 'ollama serve' (or the desktop app). Verify with: curl http://localhost:11434
Run 'ollama pull <model>' before use, or catch ResponseError and call ollama.pull(model) programmatically.
Use stream=False when tools are involved. Track https://github.com/ollama/ollama/issues/9084 for resolution.
Use pip install ollama (no hyphen suffix). Official package is at pypi.org/project/ollama.
Pass host explicitly: Client(host=os.environ.get('OLLAMA_HOST', 'http://localhost:11434'))from openai import OpenAI; client = OpenAI(base_url='http://localhost:11434/v1', api_key='ollama')
Run 'ollama signin' first. For direct cloud API access, set host='https://ollama.com' and pass Authorization header with OLLAMA_API_KEY.