Forsig is an OpenAI-compatible proxy that enforces budgets, model allowlists, velocity caps, and a circuit breaker. You call Forsig the same way you call OpenAI—just change the base URL and set your Forsig allowance key as the API key.
export OPENAI_BASE_URL="https://YOUR_WORKER.workers.dev" export OPENAI_API_KEY="sk_allow_xxx"
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.OPENAI_API_KEY, // your Forsig allowance key
baseURL: process.env.OPENAI_BASE_URL, // your Forsig worker URL
});
const res = await client.chat.completions.create({
model: "gpt-4o-mini",
messages: [{ role: "user", content: "Hello from Forsig" }],
});
console.log(res.choices[0].message.content);from openai import OpenAI
import os
client = OpenAI(
api_key=os.environ["OPENAI_API_KEY"],
base_url=os.environ["OPENAI_BASE_URL"],
)
res = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role":"user","content":"Hello from Forsig"}],
)
print(res.choices[0].message.content)Set Idempotency-Key to safely retry without double-charging.
X-Allowance-Agent-IdX-Allowance-Reserved-CentsX-Allowance-Cost-CentsX-Allowance-Balance-CentsX-Forsig-Request-Idinsufficient_balancevelocity_cap_exceededcircuit_breaker_trippedmodel_not_allowedkey_frozen