Skip to main content

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.

Command
npm install openai
Request Example
import 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_KEY available 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.env for the Node.js or Bun happy path. In Deno or edge runtimes, keep the same baseURL and request shape, but read the key from that platform’s secret API.
  • Browser use is disabled by default. Do not enable dangerouslyAllowBrowser for public client-side apps with a real gp-... key.
  • Set timeout and maxRetries explicitly on the client before production traffic.
  • If your code narrows response.usage, allow GonkaGate cost fields in the type:
TypeScript-specific notes
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_key usually means the key is missing, malformed, or not loaded in the runtime that creates the client.
  • 404 model_not_found usually means the SDK setup is fine but the model ID is stale.
  • 429 insufficient_quota means the prepaid USD balance is too low for the request.

See also

Was this page helpful?