Skip to main content
Connect OpenAI clients to Ollama. Ollama supports a subset of the OpenAI API.

Direct cloud access

Set your API key in OLLAMA_API_KEY. Install the client with pip install openai. No Ollama installation required.
The same client supports stateless Responses requests:
Choose a cloud model. The cloud API does not support stateful Responses, built-in web search through /v1/responses, or custom/freeform tool-call replay.

Local server usage

These examples connect to your local Ollama server. The client requires an API key value, but Ollama ignores it. To use cloud models through this server, sign in to Ollama.

Simple /v1/chat/completions example

basic.py

Simple /v1/responses example

responses.py

/v1/chat/completions with vision example

vision.py

Endpoints

/v1/chat/completions

Supported features

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

Supported request fields

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

/v1/completions

Supported features

  • Completions
  • Streaming
  • JSON mode
  • Reproducible outputs
  • Logprobs

Supported request fields

  • model
  • prompt
  • frequency_penalty
  • presence_penalty
  • seed
  • stop
  • stream
  • stream_options
    • include_usage
  • temperature
  • top_p
  • max_tokens
  • 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

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

Responses API

POST /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

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

Supported request fields

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

Models

For local inference, download a model before using it:
Direct cloud requests use the identifiers from https://ollama.com/api/tags and do not require a pull. Through a signed-in local server, select a cloud model such as gemma4:cloud.

Default model names on a local server

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:
Afterwards, this new model name can be specified the model field:

Setting the local 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:
Use the ollama create mymodel command to create a new model with the updated context size. Call the API with the updated model name: