TypeScript SDK
Use the official OpenAI TypeScript SDK with GonkaGate. Works with Node.js, Deno, and browsers.
For API keys, base URL, and your first request, start with the Quickstart guide .
Installation
Install the official OpenAI npm package:
terminal
npm install openaiConfiguration
Configure the client to use GonkaGate's API endpoint:
config.ts
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.gonkagate.com/v1",
apiKey: "gp-your-api-key",
});Basic Usage
Make your first chat completion request:
basic-usage.ts
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.gonkagate.com/v1",
apiKey: "gp-your-api-key",
});
const response = await client.chat.completions.create({
model: "qwen/qwen3-235b-a22b-instruct-2507-fp8",
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "Hello, how are you?" },
],
temperature: 0.7,
max_tokens: 1000,
});
console.log(response.choices[0].message.content);TypeScript Types
Extend types for GonkaGate-specific usage fields:
types.ts
// Extended usage type with GonkaGate cost fields
interface GonkaGateUsage {
prompt_tokens: number;
completion_tokens: number;
total_tokens: number;
base_cost_usd: number;
platform_fee_usd: number;
total_cost_usd: number;
}
// Type assertion for usage
const response = await client.chat.completions.create({
model: "qwen/qwen3-235b-a22b-instruct-2507-fp8",
messages: [{ role: "user", content: "Hello!" }],
});
const usage = response.usage as GonkaGateUsage;
console.log(`Cost: $${usage.total_cost_usd.toFixed(6)}`);Language-specific notes
A few TypeScript-specific tips before you ship:
- Use AbortController to cancel long-running requests.
- Prefer server-side usage to keep API keys private.
- Edge runtimes require a fetch-compatible environment.
See Streaming and Error handling for real-time responses and retry guidance.