Ollama · REST API

Use the OpenAI Python client

Point the OpenAI client at your local server. The API key is required but ignored.

from openai import OpenAI

client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")
reply = client.chat.completions.create(model="llama3.2", messages=[{"role": "user", "content": "Hello"}])

Official Ollama documentation

More rest api commands

All rest api commands · Ollama cheatsheet

Was this page helpful?