Zum Inhalt springen
GigadriveDocs

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.

  1. 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:chat and network:ai_gateway:models, as described in API keys. The key's id and secret are OAuth client credentials, and a token minted from them bills the application the key belongs to. Export the pair as GIGADRIVE_CLIENT_ID and GIGADRIVE_CLIENT_SECRET, which the SDK and the CLI both read with no further configuration.

    gigadrive login requests those same two scopes, so gigadrive ai models works straight after a sign-in. Chat needs the key: the CLI has no way to send the billing context a user token is missing.

  2. Pick a model

    Model identifiers are <owner>/<model>, for example openai/gpt-4o. An identifier the gateway does not know is rejected with HTTP 400 and code model_not_found before any provider is contacted. Models covers how to list what is actually routable for you.

  3. 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);
  4. Read what came back

    The body is OpenAI-shaped, with one addition: _gigadrive carries the provider and model_id that served the request and latency_ms. Two response headers matter more. X-Gigadrive-Request-Id is the id you look up in Request logs, and X-Gigadrive-Billing-Subject tells you which organization or application was charged.

    The gateway returns exactly one choice. Sending n above 1 is rejected rather than silently reduced.

    Set stream: true for Server-Sent Events. Frames arrive as data: {...} and the stream ends with data: [DONE]; usage is finalized before that marker, and a client that disconnects mid-stream leaves the request recorded as cancelled.