AI Gateway quickstart
Send your first chat completion through the Gigadrive Network AI Gateway.
Four steps from nothing to a completion through the Gigadrive Network AI Gateway. The endpoint is
OpenAI-compatible, so an existing OpenAI client reaches it by changing baseURL and the key.
Get a credential
Every call needs
Authorization: Bearer <token>, and the token decides which organization pays.Mint a key against the application you want billed, carrying
network:ai_gateway:chatandnetwork:ai_gateway:models, as described in API keys. The key'sidandsecretare OAuth client credentials, and a token minted from them bills the application the key belongs to. Export the pair asGIGADRIVE_CLIENT_IDandGIGADRIVE_CLIENT_SECRET, which the SDK and the CLI both read with no further configuration.gigadrive loginrequests those same two scopes, sogigadrive ai modelsworks straight after a sign-in. Chat needs the key: the CLI has no way to send the billing context a user token is missing.Pick a model
Model identifiers are
<owner>/<model>, for exampleopenai/gpt-4o. An identifier the gateway does not know is rejected with HTTP 400 and codemodel_not_foundbefore any provider is contacted. Models covers how to list what is actually routable for you.Send the request
import { GigadriveClient } from '@gigadrive/sdk'; const client = new GigadriveClient({ clientId: process.env.GIGADRIVE_CLIENT_ID, clientSecret: process.env.GIGADRIVE_CLIENT_SECRET, }); const completion = await client.aiGateway.chatCompletions({ model: 'openai/gpt-4o', messages: [{ role: 'user', content: 'Write a haiku about cold starts.' }], max_tokens: 256, }); console.log(completion.choices[0].message.content);Read what came back
The body is OpenAI-shaped, with one addition:
_gigadrivecarries theproviderandmodel_idthat served the request andlatency_ms. Two response headers matter more.X-Gigadrive-Request-Idis the id you look up in Request logs, andX-Gigadrive-Billing-Subjecttells you which organization or application was charged.The gateway returns exactly one choice. Sending
nabove 1 is rejected rather than silently reduced.Set
stream: truefor Server-Sent Events. Frames arrive asdata: {...}and the stream ends withdata: [DONE]; usage is finalized before that marker, and a client that disconnects mid-stream leaves the request recorded ascancelled.
A user token needs a billing context
A token minted from an application API key already names the application that pays. A user token does not, so send
X-Gigadrive-Organization-Id or X-Gigadrive-Application-Id on the request. Without one it fails with HTTP 403 and
code billing_context_required.
