Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

OpenAI API Provider

The openai-api provider uses the Chat Completions API. It also works with any OpenAI-compatible API endpoint (Ollama, vLLM, OpenRouter, etc.).

Configuration

SettingValue
Profile typeopenai-api
Default base URLhttps://api.openai.com/v1
CredentialAPI key (sk-...) stored in the database
Auth methodBearer token (Authorization: Bearer <key>)

Quickest Start

meka provider add openai --type openai-api --model gpt-4o

meka provider add prompts for your OpenAI API key, stores it in the database, and writes the [providers.openai] profile. To read the key from a pipe instead of prompting, pass --api-key-stdin.

Config File

meka provider add writes this for you (the key stays in the database, not here):

default_provider = "openai"

[providers.openai]
type = "openai-api"
model = "gpt-4o"

Supported Models

Any model available through the OpenAI Chat Completions API (or compatible endpoint) that supports tool calling:

  • gpt-4o, gpt-4o-mini
  • gpt-4-turbo
  • o1, o3-mini
  • Third-party models via compatible APIs

Custom Base URL

To use an OpenAI-compatible endpoint, set the profile’s base_url. Add it when creating the profile:

# Ollama (no real key; pipe a placeholder)
printf 'unused' | meka provider add ollama --type openai-api --model llama3 \
    --base-url http://localhost:11434/v1 --api-key-stdin

# OpenRouter
meka provider add openrouter --type openai-api --model anthropic/claude-sonnet-4.6 \
    --base-url https://openrouter.ai/api/v1

The resulting profile (the key, if any, lives in the database):

[providers.ollama]
type = "openai-api"
model = "llama3"
base_url = "http://localhost:11434/v1"

--base-url is also available as a per-run flag to override the profile’s value for one invocation.

API Details

Endpoint: POST {base_url}/chat/completions

Tool format: Tools are sent as function definitions:

{
  "type": "function",
  "function": {
    "name": "read_file",
    "description": "Read the contents of a file at the given path.",
    "parameters": { "type": "object", "properties": { ... } }
  }
}

Tool results: Sent back as messages with role: "tool" and the corresponding tool_call_id.

Streaming: Uses Server-Sent Events (SSE) with data: {...} lines. The stream ends with data: [DONE].