Skip to content

How-ToGPU

How to Use Ollama's OpenAI-Compatible API

How to call a local Ollama model from curl, Python or JavaScript using Ollama's official OpenAI-compatible API on http://localhost:11434/v1, including which endpoints are supported and how to pull a model first.

By , Editorial team

· 4 min read

How to Use Ollama's OpenAI-Compatible API

Ollama is useful from a terminal, but many apps expect an OpenAI-style HTTP API. Ollama provides one. If the app can point at a different base URL, you can often send that traffic to a model running on your own PC instead of to a cloud account.

Forge PC has not measured tokens per second through this API, and we have not audited every third-party client. The endpoints, fields and examples below come from Ollama's official OpenAI compatibility documentation.

This page assumes Ollama is already installed and running on Windows. If it is not, use our Ollama and LM Studio install guide first. For choosing how much memory the model needs, see how much RAM local AI uses and how much VRAM you need.

Start the local server

On a normal desktop install, Ollama's local server listens on http://localhost:11434. The OpenAI-compatible routes sit under /v1/, for example:

http://localhost:11434/v1/chat/completions

Official examples set an API key in the client because many OpenAI libraries require the field. Ollama ignores that key for local use; the docs use the placeholder value ollama.

Download a model before you call it. The OpenAI-compatibility page shows:

ollama pull llama3.2

Use whatever model you actually have. The model name in the JSON must match a name from ollama list. If you need a name that a tool insists on, such as gpt-3.5-turbo, Ollama documents ollama cp llama3.2 gpt-3.5-turbo as a way to copy an existing local model to that label. That does not download an OpenAI model; it only renames a local one.

A first request with curl

Ollama's documented curl example (with llama3.2 as the model name once you have pulled it) looks like this:

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

If Ollama is not running, or the firewall blocks port 11434, the request will fail. A simple check from the official docs is to confirm the server responds on that port.

Python and JavaScript clients

The official Python example creates an OpenAI client pointed at the local server:

from openai import OpenAI

client = OpenAI(
    base_url='http://localhost:11434/v1/',
    api_key='ollama',  # required but ignored
)

chat_completion = client.chat.completions.create(
    messages=[{'role': 'user', 'content': 'Say this is a test'}],
    model='llama3.2',
)
print(chat_completion.choices[0].message.content)

The JavaScript example is the same idea: set baseURL to http://localhost:11434/v1/ and apiKey to ollama.

You can also use /v1/responses with client.responses.create(...) and an input string. Ollama added the Responses API in version 0.13.3 and documents it as the non-stateful flavour only: no previous_response_id or conversation support.

What the compatibility layer supports

According to the official compatibility page, local /v1/chat/completions supports chat, streaming, JSON mode, reproducible outputs, vision (base64 images, not remote image URLs), tools, and reasoning controls for thinking models. It does not support logprobs, tool_choice, logit_bias, user or n.

Other documented endpoints include /v1/completions, /v1/models, /v1/embeddings, /v1/audio/speech (from Ollama v0.40.8) and /v1/audio/transcriptions. The page lists which request fields each path accepts. Do not assume every OpenAI feature exists; if a field is marked unsupported, treat a 400 error as expected.

The OpenAI API has no field for context length. If you need a different context size, Ollama says to create a Modelfile with PARAMETER num_ctx and ollama create a new model name, then call that name.

Keep this server on your own PC unless you have deliberately followed Ollama's guidance for authentication and remote access. The basic local examples are for localhost, not a public port.

Ollama also documents a cloud API at https://ollama.com/v1 that uses OLLAMA_API_KEY. That is a different product from the local server this guide is about.

Audio, embeddings and listing models

If you want to see which models the server currently exposes in OpenAI form, call GET /v1/models. Ollama notes that created is the time the model was last modified, and owned_by is the Ollama username, defaulting to "library".

/v1/embeddings accepts a string or an array of strings, plus encoding format and dimensions. It does not accept arrays of tokens.

From Ollama v0.40.8, /v1/audio/speech can generate audio with speech models. The documented defaults matter: audio is 16-bit mono at 24kHz, the default response_format is wav rather than mp3, speed is 1 only, and unsupported values return a 400 error. From v0.40.12, /v1/audio/translations can translate speech into another language, with to_language defaulting to English.

/v1/audio/transcriptions accepts a WAV file (up to 384kHz, 512MB and two hours, per the docs), a model name, an optional language code, and json, text or verbose_json as the response format. Audio longer than the model takes at once is split at pauses. These paths only work with models that actually accept audio; a plain chat model will not suddenly become a transcription engine.

Things that usually go wrong

  • Connection refused. Ollama is not running, or something else is bound to port 11434. Start the app or service and try again.

  • 404 model not found. The name in the JSON does not match ollama list. Pull the model, or fix the spelling and tag.

  • The client demands an API key. Supply a dummy value. Local Ollama ignores it.

  • A feature silently missing, or a 400 error. Check the official supported-fields list. tool_choice, logprobs and stateful Responses (previous_response_id) are not supported.

  • Context too short. You cannot set num_ctx in the OpenAI request. Create a derived model with a Modelfile, as the official page describes.

Do not paste API examples that talk to https://ollama.com/v1 into a local script and expect them to hit your PC. That base URL is the cloud service and needs OLLAMA_API_KEY.

Our verdict

Point your OpenAI-compatible client at http://localhost:11434/v1/, put any placeholder in the API key field, pull a model, and call /v1/chat/completions with that exact model name. Use the official compatibility list to see which fields work, and do not expose the port to the internet as an afterthought. We have not benchmarked clients through this API; the steps come from Ollama's official documentation.

The bottom line

Point your OpenAI-compatible client at `http://localhost:11434/v1/`, put any placeholder in the API key field, pull a model, and call `/v1/chat/completions` with that exact model name. Use the official compatibility list to see which fields work, and do not expose the port to the internet as an afterthought. We have not benchmarked clients through this API; the steps come from Ollama's official documentation.

Sources

About the author

Forge PC Staff

Editorial team

More from Forge PC Staff

Read next

How to Use LM Studio as a Local API Server

How-To

How to Use LM Studio as a Local API Server

How to turn LM Studio into a local LLM API server on http://localhost:1234: start the server from the Developer tab or with lms server start, then send OpenAI-compatible chat requests, using LM Studio's official developer docs.

Forge PC Staff

How to Use Continue in VS Code with a Local Ollama Model

How-To

How to Use Continue in VS Code with a Local Ollama Model

How to connect the Continue extension in VS Code to a local Ollama model for AI coding help without sending your code to a cloud API: official prerequisites, ollama pull, config.yaml, Autodetect, and common errors from Continue's documentation.

Forge PC Staff

NVIDIA App vs AMD Software: Which GPU Control App to Use

Versus

NVIDIA App vs AMD Software: Which GPU Control App to Use

NVIDIA App and AMD Software: Adrenalin Edition are the official apps for GeForce and Radeon PCs. We compare driver updates, overlays, recording, upscaling and one-click performance tools using NVIDIA's and AMD's own pages, not invented frame-rate tests.

Forge PC Staff

How to Install Open WebUI with Ollama on Windows

How-To

How to Install Open WebUI with Ollama on Windows

How to give Ollama a browser-based chat interface with Open WebUI on Windows: install Docker Desktop with the WSL 2 backend, run the official container, set a secret key, and connect to Ollama on port 11434.

Forge PC Staff