Local API¶
The API tab runs an OpenAI-compatible API on this computer. Other programs (scripts, editors, chat apps, anything that can talk to the OpenAI API) send requests to it, and the app answers them with your Claude, ChatGPT or Gemini subscription instead of a paid API key.
How it works¶
Each request runs the subscription's own command-line tool once, headless, in an empty folder:
| Model | Tool | Subscription |
|---|---|---|
claude/… |
Claude Code (claude -p) |
Claude Pro or Max |
codex/… |
Codex CLI (codex exec) |
ChatGPT Plus, Pro, Business… |
gemini/… |
Gemini CLI (gemini) |
Google account (Gemini Code Assist, Google AI plans) |
The tools run without their own tools (no reading or editing files, no shell commands, no web or browser), without
MCP servers, plugins or extensions, and without saving a session, so they only write a text answer and a prompt cannot
make them read files from this computer. Codex also runs without your config.toml. API keys in the app's environment (ANTHROPIC_API_KEY,
OPENAI_API_KEY, GEMINI_API_KEY…) are removed, so a request is never billed to an API key by accident. Claude
Code also runs without your own settings, hooks and plugins (and its apiKeyHelper).
While the app's proxy is running, requests go through it like your own Claude Code and Codex runs do, so they show in its traffic and get the same handling as your own runs: Claude Code and Gemini CLI through the HTTPS proxy, Codex through its listener. When the proxy is stopped, they go straight to the provider.
Because a tool process starts for every request, an answer takes a few seconds more than a direct API call. Up to four requests run at the same time; more wait their turn. Requests count against your subscription's usage limits, the same as using the tool yourself.
Provider terms
Subscriptions are meant for personal use through the providers' own apps and tools. The app only runs those official tools, but sending lots of automated requests from other programs through them may still go against a provider's terms or hit its limits. Use it for your own work, not as a shared service.
Turning it on¶
- Open the API tab and switch Local API on. It listens on
127.0.0.1:8879(only this computer). - Check that each subscription you want shows logged in (see below).
- Copy the Base URL and the API key into the other program.
The API runs while the app runs, in the tray too; quitting the app stops it. Turn it off with the same switch.
Logins¶
Each subscription has a Login choice:
- Your own login: the account you logged in with when you use
claude,codexorgeminiyourself. Nothing else to do. To change the account, log in with the tool in a terminal. Claude Code logged in with an API key (or anapiKeyHelper) is not a subscription and shows not logged in. - The app's login: a separate login the app keeps in
~/.config/ai-desktop-proxy/subscriptions/, so the API can use another account than your own. Press Log in:- Claude Code: open the login page, sign in, copy the code the page shows and paste it into the app.
- Codex CLI: open the login page and enter the code the app shows. The app notices by itself when you are done.
- Gemini CLI: open the login page, sign in with your Google account and paste the code back.
Log out removes only the app's login; your own login of the tool stays.
A tool that is not installed shows Install, which installs it with npm into ~/.local after a confirmation that
shows the exact command. It needs Node.js with npm.
Using it¶
Base URL http://127.0.0.1:8879/v1, key from the tab, sent as Authorization: Bearer <key>.
curl http://127.0.0.1:8879/v1/chat/completions \
-H "Authorization: Bearer $AI_DESKTOP_PROXY_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "claude/sonnet", "messages": [{"role": "user", "content": "Hello"}]}'
With the OpenAI Python library:
from openai import OpenAI
client = OpenAI(base_url="http://127.0.0.1:8879/v1", api_key="<key from the API tab>")
reply = client.chat.completions.create(model="codex", messages=[{"role": "user", "content": "Hello"}])
print(reply.choices[0].message.content)
| Endpoint | What |
|---|---|
GET /v1/models |
Models of the installed, logged-in subscriptions |
POST /v1/chat/completions |
An answer, at once or streamed ("stream": true), with function calling and images for Claude and Codex |
GET /docs |
Swagger UI: browse the API and try requests from the browser |
GET /openapi.json |
The OpenAPI 3.1 description, for code generators and API clients |
Swagger UI and OpenAPI¶
While the API runs, the Docs row on the API tab opens http://127.0.0.1:8879/docs in your browser. It lists
both endpoints with their request and response schemas; the model field shows the models you can use right now.
Press Authorize, paste the API key, then Try it out on an endpoint to send a real request.
http://127.0.0.1:8879/openapi.json is the same description as OpenAPI 3.1 JSON. Import it into Postman, Insomnia
or Bruno, or generate a client from it. These two pages work without the key, since they contain no secrets; the
endpoints themselves still need it. Without the key, openapi.json shows example model names; with it (as
Swagger UI sends once you authorize), the models you can use right now. The Swagger UI page loads its scripts from jsDelivr (pinned version,
integrity-checked), so it needs internet access; openapi.json does not.
Models. claude/sonnet, claude/opus, claude/haiku; codex/<model> for each model Codex lists for your
account; gemini/auto, gemini/pro, gemini/flash, gemini/flash-lite. Just claude, codex or gemini uses
the tool's default (for Codex, the first model it lists).
Function calling¶
Programs that act through functions (agents, CAD and editor plugins, anything that sends tools) work with claude/…
and codex/… models, the same way as with the OpenAI API: the answer ends with finish_reason: "tool_calls", the
program runs the functions and sends the conversation again with one role: "tool" message per call.
Behind it, the tool gets the program's functions as its only MCP server, which the app serves itself, so the model calls
them the way it was trained to. The tool process waits while the program runs a function and carries on with the
result, so each next step takes a second or two instead of a new start. If the program does not send the results
within 10 minutes, the app stops that process; a later request then starts a new one from the whole conversation.
Functions run in the program that sent them, never on this computer by the tool. Gemini models answer requests with
tools with an error for now.
Images¶
claude/… and codex/… models also read images, sent the OpenAI way as image_url parts with a base64 data: URL
(PNG, JPEG, GIF or WebP):
{"role": "user", "content": [
{"type": "text", "text": "What is on this screenshot?"},
{"type": "image_url", "image_url": {"url": "data:image/png;base64,iVBORw0KG…"}}
]}
The app does not download images from web addresses (https://…); send the image itself. A request may be up to 32 MB.
Claude Code gets the images inside its prompt; Codex gets them as files attached to the prompt, written into the
request's own temporary folder and deleted with it. Gemini models answer images with an error for now.
Limits. Audio and file parts are refused with an error. temperature,
max_tokens and similar options are accepted but ignored, because the tools do not take them. Claude Code streams
its answer as it writes; Codex and Gemini CLI send it in one piece at the end. Token counts come from the tools
(Gemini CLI reports none).
Errors come back in OpenAI's format: 401 for a wrong key or a subscription that is not logged in, 429 when
its usage limit is reached, 404 for an unknown model, 503 when the tool is not installed, 504 after 10 minutes
without an answer, 502 for anything else. The tab shows the last error.
Security¶
The API listens on 127.0.0.1 only, and every request needs the key, because any program or user on this computer
can reach the port. Requests must be addressed to 127.0.0.1, localhost or [::1] with the API's port; others
get 421, so a web page cannot reach the API by pointing its own domain at this computer. New key makes a new one; programs using the old key stop working. The key is stored in
~/.config/ai-desktop-proxy/state.json.
