Skip to content

Ollama provides compatibility with parts of the OpenAI API to help connect existing applications to Ollama.

Usage

Simple /v1/chat/completions example

Simple /v1/responses example

/v1/chat/completions with vision example

Endpoints

/v1/chat/completions

Supported features

  • [x] Chat completions
  • [x] Streaming
  • [x] JSON mode
  • [x] Reproducible outputs
  • [x] Vision
  • [x] Tools
  • [x] Reasoning/thinking control (for thinking models)
  • [ ] Logprobs

Supported request fields

  • [x] model
  • [x] messages
    • [x] Text content
    • [x] Image content
      • [x] Base64 encoded image
      • [ ] Image URL
    • [x] Array of content parts
  • [x] frequency_penalty
  • [x] presence_penalty
  • [x] response_format
  • [x] seed
  • [x] stop
  • [x] stream
  • [x] stream_options
    • [x] include_usage
  • [x] temperature
  • [x] top_p
  • [x] max_tokens
  • [x] tools
  • [x] reasoning_effort ("high", "medium", "low", "max", "none")
  • [x] reasoning
    • [x] effort ("high", "medium", "low", "max", "none")
  • [ ] tool_choice
  • [ ] logit_bias
  • [ ] user
  • [ ] n

/v1/completions

Supported features

  • [x] Completions
  • [x] Streaming
  • [x] JSON mode
  • [x] Reproducible outputs
  • [ ] Logprobs

Supported request fields

  • [x] model
  • [x] prompt
  • [x] frequency_penalty
  • [x] presence_penalty
  • [x] seed
  • [x] stop
  • [x] stream
  • [x] stream_options
    • [x] include_usage
  • [x] temperature
  • [x] top_p
  • [x] max_tokens
  • [x] suffix
  • [ ] best_of
  • [ ] echo
  • [ ] logit_bias
  • [ ] user
  • [ ] n

Notes

  • prompt currently only accepts a string

/v1/models

Notes

  • created corresponds to when the model was last modified
  • owned_by corresponds to the ollama username, defaulting to "library"

/v1/models/{model}

Notes

  • created corresponds to when the model was last modified
  • owned_by corresponds to the ollama username, defaulting to "library"

/v1/embeddings

Supported request fields

  • [x] model
  • [x] input
    • [x] string
    • [x] array of strings
    • [ ] array of tokens
    • [ ] array of token arrays
  • [x] encoding format
  • [x] dimensions
  • [ ] user

/v1/images/generations (experimental)

Note: This endpoint is experimental and may change or be removed in future versions.

Generate images using image generation models.

Supported request fields

  • [x] model
  • [x] prompt
  • [x] size (e.g. "1024x1024")
  • [x] response_format (only b64_json supported)
  • [ ] n
  • [ ] quality
  • [ ] style
  • [ ] user

/v1/responses

Note: Added in Ollama v0.13.3

Ollama supports the OpenAI Responses API. Only the non-stateful flavor is supported (i.e., there is no previous_response_id or conversation support).

Supported features

  • [x] Streaming
  • [x] Tools (function calling)
  • [x] Reasoning summaries (for thinking models)
  • [ ] Stateful requests

Supported request fields

  • [x] model
  • [x] input
  • [x] instructions
  • [x] tools
  • [x] stream
  • [x] temperature
  • [x] top_p
  • [x] max_output_tokens
  • [ ] previous_response_id (stateful v1/responses not supported)
  • [ ] conversation (stateful v1/responses not supported)
  • [ ] truncation

Models

Before using a model, pull it locally ollama pull:

shell
ollama pull llama3.2

Default model names

For tooling that relies on default OpenAI model names such as gpt-3.5-turbo, use ollama cp to copy an existing model name to a temporary name:

shell
ollama cp llama3.2 gpt-3.5-turbo

Afterwards, this new model name can be specified the model field:

shell
curl http://localhost:11434/v1/chat/completions \
    -H "Content-Type: application/json" \
    -d '{
        "model": "gpt-3.5-turbo",
        "messages": [
            {
                "role": "user",
                "content": "Hello!"
            }
        ]
    }'

Setting the context size

The OpenAI API does not have a way of setting the context size for a model. If you need to change the context size, create a Modelfile which looks like:

FROM <some model>
PARAMETER num_ctx <context size>

Use the ollama create mymodel command to create a new model with the updated context size. Call the API with the updated model name:

shell
curl http://localhost:11434/v1/chat/completions \
    -H "Content-Type: application/json" \
    -d '{
        "model": "mymodel",
        "messages": [
            {
                "role": "user",
                "content": "Hello!"
            }
        ]
    }'