> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gatelit.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Make your first authenticated LLM request through Gatelit in under five minutes.

This guide walks you through installing the SDK, issuing an auth token, and sending your first chat request. By the end you'll have a working call to `openai/gpt-4o-mini` routed through the gateway.

<Steps>
  <Step title="Install the SDK">
    Install the Gatelit SDK from npm:

    ```bash theme={null}
    npm install @gatelit/sdk
    ```

    The package includes `GatelitClient` for sending requests and `signToken` for issuing signed tokens on your backend.
  </Step>

  <Step title="Issue a signed token from your backend">
    `signToken` runs on your server (Node.js 18+, Next.js API routes, Nuxt server routes, or any edge runtime). It creates a short-lived HMAC token that authorizes a specific user to call a specific model.

    ```typescript theme={null}
    import { signToken } from "@gatelit/sdk/sign"

    const token = await signToken(
      {
        sub: "user_123",        // your user's ID
        model: "openai/gpt-4o-mini", // lock the token to one model
        ttl: 60,               // expires in 60 seconds (default)
      },
      process.env.GATELIT_SIGNING_SECRET!,
    )
    ```

    <Note>
      The signing secret must match the `GATELIT_SIGNING_SECRET` configured on your gateway. Keep it server-side only — never expose it to the browser.
    </Note>

    In a real application, expose this as an API route that your frontend calls before each request:

    ```typescript theme={null}
    // Example: Next.js API route — app/api/ai-token/route.ts
    import { signToken } from "@gatelit/sdk/sign"

    export async function GET(request: Request) {
      // Verify the user is authenticated with your own auth system first
      const token = await signToken(
        { sub: "user_123", model: "openai/gpt-4o-mini", ttl: 60 },
        process.env.GATELIT_SIGNING_SECRET!,
      )
      return Response.json({ token })
    }
    ```
  </Step>

  <Step title="Create a GatelitClient">
    Instantiate `GatelitClient` with your gateway URL and a `getToken` function. `getToken` is called automatically before each request — implement token caching here to avoid unnecessary fetches.

    ```typescript theme={null}
    import { GatelitClient } from "@gatelit/sdk"

    const client = new GatelitClient({
      gatewayUrl: "https://your-gateway.example.com",
      getToken: async () => {
        const { token } = await fetch("/api/ai-token").then(r => r.json())
        return { token, scheme: "GatelitSigned" }
      },
    })
    ```

    The `scheme` field tells the gateway which auth mode to expect. For tokens from `signToken`, use `"GatelitSigned"`.
  </Step>

  <Step title="Send a chat request">
    Call `client.chat()` with a model and messages. Models use `provider/model-name` format:

    ```typescript theme={null}
    const response = await client.chat({
      model: "openai/gpt-4o-mini",
      messages: [
        { role: "user", content: "What is an AI gateway?" },
      ],
    })

    console.log(response.content)
    // → "An AI gateway is a proxy layer that sits between..."
    ```

    <Note>
      All models follow the `provider/model-name` format. For example:

      * `openai/gpt-4o`
      * `anthropic/claude-3-5-sonnet-20241022`
      * `google/gemini-1.5-pro`
      * `mistral/mistral-large-latest`
    </Note>
  </Step>

  <Step title="Read the response">
    `client.chat()` returns a `ChatResponse` with the following shape:

    ```typescript theme={null}
    interface ChatResponse {
      content: string          // the assistant's response text
      model: string            // resolved model, e.g. "openai/gpt-4o-mini"
      usage: {
        inputTokens: number
        outputTokens: number
        totalTokens: number
      } | null
      finishReason: string | null  // e.g. "stop"
      meta: {
        requestId: string      // use this to look up the request in the dashboard
        model: string
      }
    }
    ```

    Full example putting it all together:

    ```typescript theme={null}
    const response = await client.chat({
      model: "openai/gpt-4o-mini",
      messages: [{ role: "user", content: "What is an AI gateway?" }],
    })

    console.log(response.content)
    console.log(`Used ${response.usage?.totalTokens} tokens`)
    console.log(`Request ID: ${response.meta.requestId}`)
    ```
  </Step>
</Steps>

## What's next

<CardGroup cols={2}>
  <Card title="Authentication" icon="lock" href="/authentication/overview">
    Learn when to use `GatelitSigned`, `Bearer`, or `GatelitKey` — and how to configure each.
  </Card>

  <Card title="SDK reference" icon="code" href="/sdk/gatelit-client">
    Full reference for `chat()`, `stream()`, `chatJson()`, and the `Conversation` helper.
  </Card>
</CardGroup>
