Ollama API
  1. Generate a chat completion
Ollama API
  • Endpoints
  • Conventions
  • Generate a completion
    • Overview
    • Generate request (Streaming)
      POST
    • Request (No streaming)
      POST
    • Request (with suffix)
      POST
    • Request (Structured outputs)
      POST
    • Request (JSON mode)
      POST
    • Request (with images)
      POST
    • Request (Raw Mode)
      POST
    • Request (Reproducible outputs)
      POST
    • Generate request (With options)
      POST
    • Load a model
      POST
    • Unload a model
      POST
  • Generate a chat completion
    • Overview
    • Chat Request (Streaming)
      POST
    • Chat request (No streaming)
      POST
    • Chat request (Structured outputs)
      POST
    • Chat request (With History)
      POST
    • Chat request (with images)
      POST
    • Chat request (Reproducible outputs)
      POST
    • Chat request (with tools)
      POST
    • Load a model
      POST
    • Unload a model
      POST
  • Create a Model
    • Overview
    • Create a new model
      POST
    • Quantize a model
      POST
    • Create a model from GGUF
      POST
    • Create a model from a Safetensors directory
      POST
  • Check if a Blob Exists
    • Overview
  • Push a Blob
    • Overview
  • List Local Models
    • Overview
    • Examples
  • Show Model Information
    • Overview
    • Examples
  • Copy a Model
    • Overview
    • Examples
  • Delete a Model
    • Overview
    • Examples
  • Pull a Model
    • Overview
    • Examples
  • Push a Model
    • Overview
  • Generate Embeddings
    • Overview
    • Examples
    • Request (Multiple input)
  • List Running Models
    • Overview
    • Examples
  • Generate Embedding
    • Overview
    • Examples
  • Version
    • Overview
  1. Generate a chat completion

Chat request (with tools)

POST
http://localhost:11434/api/chat
Request Request Example
Shell
JavaScript
Java
Swift
curl --location --request POST 'http://localhost:11434/api/chat' \
--header 'Content-Type: application/json' \
--data-raw '{
    "model": "gpt-3.5-turbo",
    "messages": [
        {
            "role": "user",
            "content": "Hello, who are you?"
        }
    ],
    "stream": false,
    "tools": [
        {
            "type": "function",
            "function": {
                "name": "get_current_weather",
                "description": "Get the current weather",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "property1": {
                            "type": "string",
                            "description": "City name",
                            "enum": [
                                "Beijing",
                                "Shanghai",
                                "Guangzhou"
                            ]
                        },
                        "property2": {
                            "type": "string",
                            "description": "City name",
                            "enum": [
                                "Beijing",
                                "Shanghai",
                                "Guangzhou"
                            ]
                        }
                    },
                    "required": [
                        "location"
                    ]
                }
            }
        }
    ]
}'
Response Response Example
{
  "model": "llama3.2",
  "created_at": "2024-07-22T20:33:28.123648Z",
  "message": {
    "role": "assistant",
    "content": "",
    "tool_calls": [
      {
        "function": {
          "name": "get_current_weather",
          "arguments": {
            "format": "celsius",
            "location": "Paris, FR"
          }
        }
      }
    ]
  },
  "done_reason": "stop",
  "done": true,
  "total_duration": 885095291,
  "load_duration": 3753500,
  "prompt_eval_count": 122,
  "prompt_eval_duration": 328493000,
  "eval_count": 33,
  "eval_duration": 552222000
}

Request

Body Params application/json
model
string 
required
Model name used
Example:
gpt-3.5-turbo
messages
array [object {2}] 
required
role
string 
required
Message role
Example:
user
content
string 
required
Message content
Example:
Hello, who are you?
stream
boolean 
optional
Whether to use streaming response
Example:
false
tools
array [object {2}] 
optional
type
string 
optional
Tool type
Example:
function
function
object 
optional
Examples

Responses

🟢200Success
application/json
Body
model
string 
required
created_at
string 
required
message
object 
required
role
string 
required
content
string 
required
tool_calls
array [object {1}] 
required
done_reason
string 
required
done
boolean 
required
total_duration
integer 
required
load_duration
integer 
required
prompt_eval_count
integer 
required
prompt_eval_duration
integer 
required
eval_count
integer 
required
eval_duration
integer 
required
Previous
Chat request (Reproducible outputs)
Next
Load a model
Built with