Implementation:Ollama Ollama OpenAPI Spec
| Knowledge Sources | |
|---|---|
| Domains | API, Documentation |
| Last Updated | 2025-02-15 00:00 GMT |
Overview
OpenAPI 3.1.0 specification formally defining Ollama's HTTP API, providing machine-readable documentation for all endpoints, request/response schemas, and data types.
Description
Defines all API endpoints with full request/response schemas in standard OpenAPI format. The specification covers 12 endpoints: /api/generate (text completion), /api/chat (chat completion with tool calling and thinking support), /api/embed (embedding generation), /api/tags (list local models), /api/ps (list running models), /api/show (model details), /api/create (create model from Modelfile), /api/copy (copy a model), /api/pull (download from registry), /api/push (upload to registry), /api/delete (remove model), and /api/version (server version). Includes comprehensive schemas for ModelOptions (sampling parameters like temperature, top_k, top_p, min_p, stop sequences), message structures with role/content/tool_calls, streaming response formats, and tool definitions. Server defaults to http://localhost:11434 with optional bearer token authentication.
Usage
Used by the Mintlify documentation site for interactive API playgrounds and by code generation tools to produce type-safe client libraries. Also serves as the canonical reference for API consumers.
Code Reference
Source Location
- Repository: Ollama
- File: docs/openapi.yaml
- Lines: 1-1491
Signature
openapi: 3.1.0
info:
title: Ollama API
version: 0.1.0
servers:
- url: http://localhost:11434
paths:
/api/generate: # POST - Generate text completion
/api/chat: # POST - Generate chat message
/api/embed: # POST - Generate embeddings
/api/tags: # GET - List local models
/api/ps: # GET - List running models
/api/show: # POST - Show model details
/api/create: # POST - Create model from Modelfile
/api/copy: # POST - Copy a model
/api/pull: # POST - Pull model from registry
/api/push: # POST - Push model to registry
/api/delete: # DELETE - Delete a model
/api/version: # GET - Get server version
Import
# Reference the spec at docs/openapi.yaml
# No import needed - this is a standalone specification file
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | Model name for all generation endpoints |
| prompt | string | No | Text prompt for /api/generate |
| messages | array | No | Chat messages for /api/chat |
| input | string/array | No | Text(s) for /api/embed |
| stream | boolean | No | Enable streaming responses (default: true) |
| options | ModelOptions | No | Sampling parameters (temperature, top_k, top_p, etc.) |
Outputs
| Name | Type | Description |
|---|---|---|
| response | string | Generated text (for /api/generate) |
| message | object | Assistant message with content and optional tool_calls (for /api/chat) |
| embeddings | array | Embedding vectors (for /api/embed) |
| models | array | List of model information objects (for /api/tags) |
| done | boolean | Whether generation has completed |
| total_duration | integer | Total processing time in nanoseconds |
Usage Examples
# Example: Generate endpoint request
POST /api/generate
{
"model": "gemma3",
"prompt": "Why is the sky blue?",
"stream": false,
"options": {
"temperature": 0.8,
"top_p": 0.9,
"seed": 42
}
}
# Example: Chat endpoint with tool calling
POST /api/chat
{
"model": "qwen3",
"messages": [
{"role": "user", "content": "What is the weather in Paris?"}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_current_weather",
"parameters": {"type": "object", "properties": {"location": {"type": "string"}}}
}
}
]
}