mock-ollama Uniformly proxy the real LLM interface to the local machine.
It accepts the OpenAI Chat Completions, Anthropic Messages, and OpenAI Responses protocols;/api/version、/api/tags、/api/show It only provides Ollama discovery/metadata compatibility,does not support Ollama /api/chat and /api/generate。
Installation
npm install -g mock-ollama
mock-ollama -h
Cursor temporary public network mode additionally requires installing cloudflared。
Start the main service
When the upstream is OpenAI Chat Completions:
mock-ollama \
--url "https://open.bigmodel.cn/api/paas/v4" \
--apikey "你的上游密钥" \
--api-style chat
Environment variables can also be used:
export MOCK_OLLAMA_BASE_URL="https://api.example.com/v1"
export MOCK_OLLAMA_API_KEY="你的上游密钥"
mock-ollama --api-style responses --bridge
By default listens on http://localhost:11434。
Protocols and bridge
| Client protocol | Local route | Typical client |
|---|---|---|
| Chat Completions | /v1/chat/completions |
Cursor, OpenAI-compatible SDK |
| Anthropic Messages | /v1/messages |
Claude Code |
| OpenAI Responses | /v1/responses |
Codex、GPT-5.6 |
| Parameter | Description |
|---|---|
--api-style auto|anthropic|responses|chat |
Specify the upstream API format, default auto auto-detect |
--bridge |
Enable automatic 3×3 interconversion among the Anthropic, Responses, and Chat protocols |
--url / MOCK_OLLAMA_BASE_URL |
Upstream API root address |
--apikey / MOCK_OLLAMA_API_KEY |
Upstream API Key |
--host / --port |
Main service listening address and port, default localhost:11434 |
--quiet |
Disable verbose console logging |
When the upstream and client protocols differ, --bridgemust be enabled. Common combinations:
# Claude Code → GPT-5.6 / Responses 上游
mock-ollama --url "https://api.example.com/v1" --apikey "你的上游密钥" --api-style responses --bridge
# Codex / GPT-5.6 客户端 → Claude / Anthropic 上游
mock-ollama --url "https://api.anthropic.com" --apikey "你的上游密钥" --api-style anthropic --bridge
The bridge supports text, SSE, tool calls, system messages, and reasoning; when disabled, each protocol is transparently forwarded along the original path and with the original request body.
Claude Code
Claude Code uses the Anthropic Messages route. If the upstream is not Anthropic, the main service must include --bridge。
olm_claude() {
local model="${1:-claude-sonnet-4-6}"
shift || true
ANTHROPIC_AUTH_TOKEN=ollama \
ANTHROPIC_BASE_URL=http://localhost:11434 \
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 \
ANTHROPIC_MODEL="$model" \
ANTHROPIC_DEFAULT_SONNET_MODEL="$model" \
ANTHROPIC_DEFAULT_OPUS_MODEL="$model" \
ANTHROPIC_DEFAULT_HAIKU_MODEL="$model" \
claude --permission-mode acceptEdits --model "$model" "$@"
}
# 例:通过 Responses 上游运行 Claude Code
olm_claude claude-sonnet-4-6
Codex and GPT-5.6
Codex uses the OpenAI Responses route. Create a temporary configuration file without modifying the existing ~/.codex/config.toml:
# /tmp/mock-ollama-codex.toml
model_provider = "mock-ollama"
model = "gpt-5.6-terra"
[model_providers.mock-ollama]
name = "mock-ollama"
base_url = "http://localhost:11434/v1"
env_key = "MOCK_OLLAMA_CODEX_API_KEY"
wire_api = "responses"
requires_openai_auth = false
At startup, provide any non-empty local Bearer value; the main service uses its own MOCK_OLLAMA_API_KEY to access the real upstream:
mkdir -p /tmp/mock-ollama-codex-home
cp /tmp/mock-ollama-codex.toml /tmp/mock-ollama-codex-home/config.toml
MOCK_OLLAMA_CODEX_API_KEY=ollama \
CODEX_HOME=/tmp/mock-ollama-codex-home \
codex --model gpt-5.6-terra
If the upstream is not Responses, add --bridgewhen starting the main service. You can replace gpt-5.6-terra with the actual upstream model name.
Cursor BYOK
Do not expose 11434 with management interfaces directly to the public network. Cursor uses an independent minimal public network entry point:
# 1. 主服务只留在本机
mock-ollama \
--url "https://api.example.com/v1" \
--apikey "你的上游密钥" \
--api-style responses \
--bridge
# 2. Cursor 专用入口,默认启动临时 Cloudflare Tunnel
mock-ollama --cursor
The second command prints the configuration required for Cursor Settings → Models:
- Open
Override OpenAI Base URL - Fill in the printed
Base URL - Fill in the printed
OpenAI API Key - Add any of the printed model names; multiple models can be added for free switching
| Parameter | Default value | Description |
|---|---|---|
--cursor |
- | Start the Cursor BYOK dedicated entry point |
--cursor-port |
11435 |
Cursor local loopback port |
--cursor-api-key |
Randomly generated | Public network entry Bearer key |
--cursor-upstream |
http://localhost:11434 |
Already-started main service |
--cursor-tunnel |
quick |
quick Start a temporary Tunnel,off only start the local entry point |
The Cursor entry point only exposes /healthz、/v1/models、/v1/chat/completions; except for health checks, all require Bearer authentication.trycloudflare.com The temporary address changes on every restart; for long-term use, a controlled domain and Cloudflare Access should be configured.
Check the service
curl http://localhost:11434/api/version
curl http://localhost:11434/api/tags
curl -X POST http://localhost:11434/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "你的模型名",
"messages": [{"role": "user", "content": "你好"}]
}'