Skip to content

Open WebUI API Guide: Enable API Keys, Chat Completions and OpenAI Clients

7–10 minutes
Woman on a rooftop terrace holding a tablet with an OPEN WEBUI API card, hook one key every model

The Open WebUI API lets your own scripts, apps and coding tools use every model connected to your Open WebUI server through one URL and one key.

It speaks the OpenAI Chat Completions format, has an Anthropic Messages endpoint, and can pass requests straight through to Ollama. Your custom models, filters and even MCP tools can run behind it.

There is one catch most people hit first: API keys are switched off by default. Turn them on, create a key, and you can call Open WebUI from curl, Python or any OpenAI-compatible client in minutes.

This guide covers enabling API keys, creating a key, your first request, connecting OpenAI-compatible clients, using custom models and tools, the Anthropic and Ollama endpoints, managing models from scripts, security and fixes. It follows the official Open WebUI documentation as of December 2026.

TL;DR

  • Enable: admin opens Settings > Authentication, turns API Keys on and saves.
  • Key: Settings > Account > API keys > Show > Create new secret key. Keys look like sk- plus 32 hex characters.
  • Chat: POST /api/chat/completions with Authorization: Bearer YOUR_KEY.
  • OpenAI clients: base URL http://localhost:3000/api/v1.
  • Also: Anthropic format at /api/v1/messages, raw Ollama at /ollama/api/....
  • One key per account: creating a new key replaces the old one instantly.

What You Can Do With the API

Endpoint Use
GET /api/models List all models you can use
POST /api/chat/completions OpenAI-style chat, with custom model settings applied
POST /api/v1/messages Anthropic Messages format
/ollama/api/... Pass-through to the native Ollama API
/api/v1/models/export, /import, /sync Manage custom models as JSON
/api/v1/files/, /api/v1/knowledge/ Upload files and build knowledge for RAG

The docs note the API changes often and is no longer fully documented. For the latest list, start the backend with ENV=dev and open Swagger at /docs or the schema at /openapi.json. The Docker image sets ENV=prod, which disables both, so only switch this on for a local test instance.

Enable API Keys

  1. Sign in as an administrator.
  2. Open Settings > Authentication in the admin section.
  3. Turn API Keys on and click Save.
  4. Optional: turn on API Key Endpoint Restrictions and list allowed paths, for example /api/v1/models,/api/v1/chat/completions.

This is the master switch. When it is off nobody can create or use a key, and existing keys stop working.

For non-admin users, also grant the API Keys feature permission:

  • Everyone: Admin Panel > Users > Groups > Default Permissions > Features Permissions > API Keys.
  • Only some users (better): create a group such as “API Users”, toggle API Keys under its Features Permissions, and add only the accounts that need it.

Our Open WebUI users, groups and permissions guide shows the group screens.

Create Your API Key

  1. Click your profile icon at the bottom left.
  2. Open Settings > Account.
  3. Scroll to API keys and click Show next to Secrets.
  4. Click Create new secret key.
  5. Copy it with the copy button and store it in a password manager or secrets store.

Each account has exactly one key. Create new key replaces it, and Delete removes it; either way the old key stops working immediately. Admins also see a JWT Token there. That is the browser session token, not an API key, and it expires with the session.

A key acts as you: it inherits your role and group permissions, checked again on every request.

Make Your First Request

List models first, so you know the exact model ID to use:

curl -H "Authorization: Bearer YOUR_API_KEY" \
  http://localhost:3000/api/models

Then send a chat request:

curl -X POST http://localhost:3000/api/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen3.6:27b",
    "messages": [{"role": "user", "content": "Why is the sky blue?"}]
  }'

The same in Python:

import requests

url = "http://localhost:3000/api/chat/completions"
headers = {"Authorization": "Bearer YOUR_API_KEY"}
data = {
    "model": "qwen3.6:27b",
    "messages": [{"role": "user", "content": "Why is the sky blue?"}],
}
r = requests.post(url, headers=headers, json=data)
print(r.json()["choices"][0]["message"]["content"])

Use the port your instance runs on. Docker installs usually map to 3000; a bare Python install often uses 8080. If Open WebUI is not set up yet, follow our Open WebUI with Ollama setup guide.

Connect OpenAI-Compatible Clients

Most apps, IDE extensions and SDKs that support “OpenAI-compatible” endpoints work with Open WebUI.

Setting Value
Base URL http://localhost:3000/api/v1
API key Your sk-... key
Model An ID from GET /api/v1/models
from openai import OpenAI

client = OpenAI(base_url="http://localhost:3000/api/v1", api_key="YOUR_API_KEY")
resp = client.chat.completions.create(
    model="qwen3.6:27b",
    messages=[{"role": "user", "content": "Give me 3 blog title ideas."}],
)
print(resp.choices[0].message.content)

If endpoint restrictions are on, allow both /api/v1/models and /api/v1/chat/completions. The check uses the exact path, so /api/chat/completions alone does not cover the /api/v1 alias.

Behind a proxy that already uses the Authorization header? Send the key in x-api-key instead, or rename that header with CUSTOM_API_KEY_HEADER.

Use Custom Models and Tools

A custom model from Workspace > Models works over the API by its ID, but only /api/chat/completions (and /api/v1/chat/completions) applies its base model, system prompt, parameters and filters.

Route Custom model handling
/api/chat/completions Base model, system prompt, parameters and filters apply
/openai/chat/completions System prompt and parameters only; no knowledge, tools or filters
/openai/responses Nothing applies; send the provider’s own model ID

The web UI adds some settings itself, so an API caller must send them:

  • Tools: send their IDs in tool_ids. MCP servers use server:mcp:<server-id>.
  • Default features: send them in features.
  • Toggleable filters: send their IDs in filter_ids.
curl -X POST http://localhost:3000/api/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen3.6:27b",
    "messages": [{"role": "user", "content": "Use the MCP tool if it helps."}],
    "tool_ids": ["server:mcp:YOUR_MCP_SERVER_ID"]
  }'

Parameters you send, such as temperature or max_tokens, always win over the model’s own values. More on building these presets in our Open WebUI custom models guide, and on tool servers in our Open WebUI MCP guide.

Anthropic Messages Endpoint

Tools built for the Anthropic API can point at Open WebUI too. Endpoints are POST /api/message and POST /api/v1/messages, and both Authorization: Bearer and Anthropic’s x-api-key header work. Requests are converted to Chat Completions, routed through your models and filters, and converted back, streaming included.

curl -X POST http://localhost:3000/api/v1/messages \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen3.6:27b",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Hello"}]
  }'

Reasoning output comes back as thinking blocks, and reasoning_effort or output_config.effort map to the model’s effort setting. Extra parameters are dropped unless the connection lists them in Passthrough params.

Ollama Proxy

For raw Ollama features, Open WebUI passes requests through at /ollama/<api>, protected by your Open WebUI key. This is a safe way to share Ollama on a network without exposing port 11434.

curl http://localhost:3000/ollama/api/tags \
  -H "Authorization: Bearer YOUR_API_KEY"

curl http://localhost:3000/ollama/api/generate \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "qwen3.6:27b", "prompt": "Why is the sky blue?"}'

Request bodies follow the native Ollama API; see our Ollama API guide for every field.

Manage Models From Scripts

Custom models are plain JSON, so you can keep them in git.

# Save all custom models to a file
curl -H "Authorization: Bearer YOUR_API_KEY" \
  http://localhost:3000/api/v1/models/export > models.json

# Make the instance match the file (admin; deletes models not in it)
curl -X POST -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"models\": $(cat models.json)}" \
  http://localhost:3000/api/v1/models/sync

Use /api/v1/models/import instead of /sync for additive updates that never delete anything.

Security Best Practices

  • Treat the key like a password. Never commit it to git or paste it in public channels.
  • Give each integration its own non-admin account (for example ci-pipeline), since an account holds only one key.
  • Use API Key Endpoint Restrictions to allow only the routes you need.
  • If a key leaks, create a new one at once; the old key dies instantly.
  • Admins can Rotate or Delete any user’s key from Admin Panel > Users, or kill all keys with the global toggle.
  • Put Open WebUI behind HTTPS before exposing it outside your network.

Troubleshooting

I cannot see the API keys section

The global API Keys toggle is off, or your account lacks the API Keys feature permission. Ask an admin.

401 Unauthorized

The key is wrong, was replaced, or keys are switched off globally. Check the header is Authorization: Bearer sk-....

“Model not found”

Use the exact ID from /api/models. For a custom model, you also need access to its base model.

My custom model ignores its tools over the API

Tools are added by the web UI, not the server. Send tool_ids yourself.

/docs returns 404

The Docker image runs with ENV=prod. Set ENV=dev on a local test container and recreate it.

Client works for models list but not chat

Endpoint restrictions block one path. Allow both /api/v1/models and /api/v1/chat/completions.

429 errors

The upstream provider rate-limited you. Open WebUI passes its Retry-After header through, so back off and retry.

FAQ

Is the Open WebUI API free?

Yes. It is part of self-hosted Open WebUI. Online models behind it are billed by their providers.

Is it OpenAI compatible?

Yes. Use /api/v1 as the base URL in any OpenAI-compatible client.

Can I use Claude Code or Anthropic SDKs with it?

Tools that speak the Anthropic Messages API can use /api/v1/messages with your key in x-api-key.

Can several apps share one key?

They can, but it is better to create a separate account and key per app, so you can revoke one without breaking the others.

Does the API support streaming?

Yes. Send "stream": true as with the OpenAI API.

Can I upload files for RAG through the API?

Yes. Upload with /api/v1/files/, add files to a knowledge collection, then reference it in a chat request.

Sources

Free weekly email

Get new AI guides every week

One short weekly email with our newest local AI, ComfyUI and AI tool guides. No spam, no pop-ups, just the good stuff.

Free. Unsubscribe anytime in one click. We only use your email to send this newsletter. See our privacy policy.

Woman on a rooftop terrace holding a tablet with an OPEN WEBUI API card, hook one key every model