Quickstart: Budget Lock
Route OpenAI-compatible or Anthropic calls through the RaksHex gateway, set a hard monthly cap, and verify that over-cap calls fail with HTTP 403.
1. Request access
RaksHex is in private beta. Access is by request. You do not need a RaksHex SDK: you keep your OpenAI or Anthropic SDK and change two lines. After your workspace is approved, you receive a RaksHex gateway key (rkx_...) and the gateway URL.
2. Change the base URL & headers
Point your client at the RaksHex gateway for OpenAI-compatible (/v1/chat/completions) or Anthropic (/v1/messages) calls, authenticate with your RaksHex key, and pass x-rakshex-agent-id to enforce per-agent caps.
OpenAI SDK (chat completions, Responses API, embeddings). The base URL ends in /v1:
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.RAKSHEX_GATEWAY_KEY, // rkx_... (not your OpenAI key)
baseURL: "https://rakshex-gateway.rakshex.workers.dev/v1",
});
const r = await client.responses.create({ model: "gpt-4o-mini", input: "Hello" });
Python:
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["RAKSHEX_GATEWAY_KEY"],
base_url="https://rakshex-gateway.rakshex.workers.dev/v1",
)
OpenAI Agents SDK (Python). It needs an async client. Its tracing uploads to OpenAI with your OpenAI key, so turn it off or keep an OpenAI key for it:
import os
from openai import AsyncOpenAI
from agents import set_default_openai_client, set_tracing_disabled
set_default_openai_client(AsyncOpenAI(
api_key=os.environ["RAKSHEX_GATEWAY_KEY"],
base_url="https://rakshex-gateway.rakshex.workers.dev/v1",
))
set_tracing_disabled(True)
Anthropic SDK. The base URL has no /v1 (the SDK adds it):
import Anthropic from "@anthropic-ai/sdk";
const anthropic = new Anthropic({
apiKey: process.env.RAKSHEX_GATEWAY_KEY,
baseURL: "https://rakshex-gateway.rakshex.workers.dev",
});
Groq or another OpenAI-compatible host: same as OpenAI, plus the header x-rakshex-provider: openai_compatible (we store that host's URL and key for your workspace).
Per-agent caps: use a gateway key bound to that agent (create it in the console with "Bind to agent"). An unbound key can also send x-rakshex-agent-id, but then the agent cap only applies when the header is sent.
3. Set a hard cap
When your workspace is approved you also get an owner token (rkxo_...). Keep it for the account owner only; never put it in an app. The simplest way: sign in at rakshex.in/console with it and set the cap there. Or use the API:
curl -X PUT https://rakshex-gateway.rakshex.workers.dev/v1/rakshex/workspace/caps -H "Authorization: Bearer $RAKSHEX_OWNER_TOKEN" -H "content-type: application/json" -d '{"scope":"workspace","scopeId":null,"limitUsd":50}'
Use "scope":"agent" or "scope":"key" with a scopeId for a cap per agent or per gateway key. A change takes effect on the next call. Gateway keys (rkx_...) are refused here, so an agent can never raise its own cap.
Each cap is in US dollars per calendar month (UTC) and resets on the 1st. Alerts at 50%, 80% and 100% can be sent to a webhook you give us, signed with HMAC-SHA256.
4. What a refusal looks like
Every applicable cap (workspace, agent, and gateway key) is checked together before the call is sent. If reserving the worst-case call cost would exceed any cap, the gateway refuses immediately with HTTP 403:
HTTP/1.1 403 Forbidden
Content-Type: application/json
{
"error": {
"message": "Budget Lock: workspace cap of $50 would be exceeded ($49.98 spent this month)",
"type": "policy_error",
"param": null,
"code": "rakshex_budget_blocked"
}
}
The provider is never called for a refused request, so it costs nothing. On /v1/messages the refusal uses Anthropic's error format: HTTP 403 with {"type":"error","error":{"type":"permission_error",...}}.
Supported endpoints
POST /v1/chat/completions: OpenAI and OpenAI-compatible, with streaming.POST /v1/responses: the OpenAI Responses API (used by the Agents SDK), with streaming. Function tools only: hosted tools such as web search and file search, andbackgroundmode, are refused with HTTP 400, because they are billed outside token usage and a cap could not hold.POST /v1/embeddings: OpenAI embeddings.POST /v1/messages: Anthropic, with streaming.
Honest limits
Only calls routed through the RaksHex gateway are capped. Calls made directly to a provider are not metered or blocked.
Each gateway key can make at most 60 calls per minute. Over that, the gateway answers HTTP 429 with a retry-after header and code rakshex_rate_limited, before any spend. If your app needs more, use one key per service or ask us.
If you send no output limit, the gateway sets one (4,096 tokens) so a long answer cannot pass your cap. Set your own max_tokens for longer answers.