OpenAI API gateway: proxy GPT calls with per-feature cost tracking and budget limits
Route OpenAI SDK calls through an OpenAI-compatible gateway by changing base_url. Track GPT spend per feature, team and user, and cap it with budgets enforced before the call — Python, Node.js and curl examples.
Cognocient AI is an OpenAI-compatible gateway: the OpenAI SDK you already use talks to it unchanged. You swap base_url and the API key, and every GPT call gets per-feature cost attribution, budgets enforced before the call, and a kill switch.
Setup
- Add your OpenAI API key in Settings → AI Providers. It is encrypted at rest and never shown again.
- Create a proxy key (
sk-cog-...) in Settings → Proxy Keys. - Change two lines in your client:
Setting OPENAI_BASE_URL=https://api.cognocient.com/v1 and OPENAI_API_KEY=sk-cog-... in the environment works too: the official SDKs read both, so tools that wrap the OpenAI SDK pick the gateway up with no code change.
What works
| Endpoint | Through the gateway | Notes |
|---|---|---|
/v1/chat/completions | ✅ | Streaming, function/tool calling, structured output, vision |
/v1/responses | ✅ | Stateless: send the full conversation; hosted tools are not supported. See Responses API |
/v1/embeddings | ✅ | Costed per input token |
/v1/images/generations | ✅ | dall-e-3, dall-e-2, gpt-image-1, priced per image |
/v1/audio/* | ✅ | Transcription, translation, speech. See Audio & rerank |
/v1/files, /v1/batches | ✅ Growth plan | Batch discount attributed to your tags. See Batch API |
Model names are forwarded exactly as you send them, so a model OpenAI releases today works today. Pricing comes from a daily catalogue sync; until a brand-new model is priced, its calls are costed at a conservative fallback rate rather than $0 (see New models).
Streaming and token usage
On streamed calls the gateway asks OpenAI for a final usage chunk (stream_options.include_usage), so cost is computed from OpenAI's own token counts, not an estimate. You don't need to set it yourself, and your client will see one extra chunk with an empty choices array at the end of the stream, which the official SDKs handle.
Tag calls by feature, team and user
Headers set on the client tag every call it makes. Per-request tags go in extra_headers:
The full list is in Attribution headers. Untagged calls still appear, under untagged.
Cap OpenAI spend
Create a budget in Budgets → New Budget on a feature, department, user, run or the whole account. It is checked before the call is forwarded, using a reservation for the call's worst-case cost, so concurrent calls can't jointly overshoot it. When it runs out you choose what happens:
- Block — the call returns
429with a JSON error your code can catch. - Degrade — the call runs on a cheaper model you pick (for example
gpt-4o→gpt-4o-mini) and the response carriesx-cog-degraded: true. - Alert — the call goes through and you get an email or Slack alert.
See Budget enforcement for how reservations, streaming and timeouts are counted.
Azure OpenAI takes precedence for GPT models
If you also connect an Azure OpenAI key, model names containing gpt-, o1 or o3 are sent to your Azure deployment instead of OpenAI. See Azure OpenAI.
Frequently asked questions
Related articles
Supported Providers
OpenAI, Anthropic, Gemini, Mistral, Groq, Together, Azure, AWS Bedrock, Vertex AI, and custom OpenAI-compatible endpoints.
Anthropic (Claude)
Claude through the OpenAI SDK (translated) or the native Anthropic SDK (passthrough), with prompt-cache-aware cost.
Google Gemini
Gemini models with the OpenAI SDK, embeddings and Imagen, with per-feature cost and budgets.