> ## 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.

# GatelitClient

> The main client class for interacting with the Gatelit gateway.

<Note>
  This page is auto-generated from source code on every push to `main`.
  Edit JSDoc in `packages/sdk/src/client.ts` to update it.
</Note>

## Constructor

```ts theme={null}
new GatelitClient(config: GatelitClientConfig)
```

| Parameter           | Type                                                    | Description                                          |
| ------------------- | ------------------------------------------------------- | ---------------------------------------------------- |
| `config.gatewayUrl` | `string`                                                | Base URL of your deployed Gatelit gateway            |
| `config.getToken`   | `() => Promise<{ token: string; scheme: TokenScheme }>` | Called before each request to get a fresh auth token |

***

## Methods

### `chat(options)`

Sends a non-streaming chat request and returns the full response.

```ts theme={null}
async chat(options: ChatOptions): Promise<ChatResponse>
```

```ts theme={null}
const response = await client.chat({
  model: "openai/gpt-4o",
  messages: [{ role: "user", content: "Hello" }],
  maxTokens: 500,
  temperature: 0.7,
})

console.log(response.content)   // "Hello! How can I help?"
console.log(response.usage)     // { inputTokens: 10, outputTokens: 8, totalTokens: 18 }
```

**Parameters:** See [`ChatOptions`](/sdk/typescript/reference/types#chatoptions)

**Returns:** [`ChatResponse`](/sdk/typescript/reference/types#chatresponse)

***

### `stream(options)`

Returns an async iterator that yields token deltas as they arrive.

```ts theme={null}
stream(options: ChatOptions): AsyncIterable<StreamChunk>
```

```ts theme={null}
for await (const chunk of client.stream({
  model: "anthropic/claude-3-5-haiku-20241022",
  messages: [{ role: "user", content: "Write a poem" }],
})) {
  process.stdout.write(chunk.delta)
  if (chunk.usage) console.log("\nTokens:", chunk.usage)
}
```

**Returns:** `AsyncIterable<`[`StreamChunk`](/sdk/typescript/reference/types#streamchunk)`>`

***

### `chatJson<T>(options)`

Sends a chat request with structured JSON output and returns the parsed result as `T`.

```ts theme={null}
async chatJson<T>(options: ChatOptions & { outputSchema: OutputSchema }): Promise<T>
```

```ts theme={null}
const result = await client.chatJson<{ name: string; age: number }>({
  model: "openai/gpt-4o",
  messages: [{ role: "user", content: "Extract: Alice is 30 years old." }],
  outputSchema: {
    mode: "json_schema",
    type: "object",
    properties: {
      name: { type: "string" },
      age: { type: "integer" },
    },
    required: ["name", "age"],
  },
})

console.log(result.name) // "Alice"
console.log(result.age)  // 30
```

**Returns:** `Promise<T>`

***

### `conversation(options?)`

Creates a new `Conversation` instance for multi-turn chat.

```ts theme={null}
conversation(options?: ConversationOptions): Conversation
```

See [`Conversation`](/sdk/typescript/reference/Conversation).
