OpenAI proxy server

An OpenAI proxy server is a small program that takes your OpenAI API calls, forwards them to OpenAI, and records what each one cost on the way through. RelayPlane is a free, MIT licensed one that runs on your own machine on port 4100 and speaks the OpenAI Chat Completions API.

Setup is four lines in a terminal. Your existing code keeps working.

npm install -g @relayplane/proxy
export OPENAI_API_KEY=sk-...
relayplane start
export OPENAI_BASE_URL=http://localhost:4100

What it does with each request

Your app sends a request to localhost:4100 instead of api.openai.com. The proxy reads it, works out the cost, and passes it on. The OpenAI endpoint it handles is /v1/chat/completions, with streaming and tool calls supported, per the how it works docs.

Because it also handles the Anthropic Messages API on the same port, one proxy can sit in front of an OpenAI client and Claude Code at once, and the cost numbers land in one place.

Point your code at it

Anything that reads OPENAI_BASE_URL picks it up with no code change. If your client takes a base URL in code instead, set it to http://localhost:4100/v1, as the Node.js proxy walkthrough does. Your provider key stays in your own environment. It does not go to us.

If the dashboard stays empty, the variable is almost always unset in the terminal where your app runs. Print it with echo $OPENAI_BASE_URL.

See what a run costs

Run relayplane stats for a cost breakdown by model, or open http://localhost:4100 for the dashboard. The OpenAI usage page cannot give you that. You get spend per run as it happens, not a daily total the next morning.

Cap it before it drains the budget

A looping agent can spend a lot before anyone looks. A cap checks the request before it is forwarded, so the call that would cross the limit is the one that gets blocked.

relayplane cap set --day 10
relayplane budget status

The breach action is block, warn or downgrade. The budget cap docs have the config block, and capping spend per task covers a limit on a single job.

What to watch for

The proxy lives on one machine. If your app runs on a server or in a container, run the proxy there too, or the base URL will point at the wrong localhost. The VPS deployment docs cover the server case.

The cap counts the API price of the tokens, which is an estimate and can differ from your invoice. Check the first few days against the OpenAI billing page before you rely on it.

Other options

LiteLLM is the better pick if you want virtual keys and team budgets across many users. See the LiteLLM comparison. For the wider picture of what a proxy does and how it differs from a gateway, read what an LLM proxy is.

Start the proxy

Free and MIT licensed. Node.js 18 or newer.

Open the quickstart