TypeScript SDK
Send chat.completions requests to GonkaGate from TypeScript with the official OpenAI SDK.
Send one chat.completions request from TypeScript with the official OpenAI SDK, then adapt the same client shape to your runtime.
Minimum working example
Install openai, set GONKAGATE_API_KEY, and run one request.
npm install openaiimport OpenAI from "openai";
const apiKey = process.env.GONKAGATE_API_KEY;
if (!apiKey) {
throw new Error("Set GONKAGATE_API_KEY before running this example.");
}
const client = new OpenAI({
baseURL: "https://api.gonkagate.com/v1",
apiKey
});
async function main() {
const response = await client.chat.completions.create({
model: "qwen/qwen3-235b-a22b-instruct-2507-fp8",
messages: [{ role: "user", content: "Hello, GonkaGate!" }]
});
console.log(response.choices[0]?.message?.content);
console.log(response.usage);
}
main().catch(console.error);Expected result: you get text in response.choices[0]?.message?.content, and response.usage is available for logging or cost inspection.
Use a current GonkaGate model ID before you send real traffic. The example value above is only illustrative.
What you need before you use it
GONKAGATE_API_KEYavailable in the runtime where this script runs- A current GonkaGate model ID for the workload you want to call
- A server-side place to keep the key out of browsers and public bundles
TypeScript-specific notes
- The official SDK supports Node.js, Deno, Bun, Cloudflare Workers, and Vercel Edge Runtime.
- The example uses
process.envfor the Node.js or Bun happy path. In Deno or edge runtimes, keep the samebaseURLand request shape, but read the key from that platform’s secret API. - Browser use is disabled by default. Do not enable
dangerouslyAllowBrowserfor public client-side apps with a realgp-...key. - Set
timeoutandmaxRetriesexplicitly on the client before production traffic. - If your code narrows
response.usage, allow GonkaGate cost fields in the type:
type GonkaGateUsage = {
prompt_tokens: number;
completion_tokens: number;
total_tokens: number;
base_cost_usd: number;
platform_fee_usd: number;
total_cost_usd: number;
};
// After `await client.chat.completions.create(...)`
const usage = response.usage as GonkaGateUsage | undefined;
if (usage) {
console.log(`Total cost: $${usage.total_cost_usd.toFixed(6)}`);
}Common errors and limits
401 invalid_api_keyusually means the key is missing, malformed, or not loaded in the runtime that creates the client.404 model_not_foundusually means the SDK setup is fine but the model ID is stale.429 insufficient_quotameans the prepaid USD balance is too low for the request.
See also
- Authentication and API Keys for key creation, secure storage, and rotation.
- OpenAI SDK compatibility for the shared GonkaGate rules that stay the same across runtimes.
- API Reference Overview when this TypeScript request works and you need exact request fields, streaming behavior, or runtime-independent failure policy.
- OpenAI to GonkaGate Migration Guide if you are switching already-working OpenAI-compatible code.
- Framework & Tool Guides if you use Vercel AI SDK, LangChain, or another wrapper instead of the raw OpenAI client.
- Claude Code, Cursor, Kilo Code, OpenCode, and OpenClaw if your TypeScript workflow runs through an agent-owned tool path.
- Get Models endpoint reference for the current machine-readable model IDs.
Was this page helpful?