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

# Configuration

> Configure the Triqai SDK with custom options for retries, timeouts, headers, and debug hooks

The `Triqai` client accepts a configuration object as the second argument. All options are optional and have sensible defaults.

## Full Configuration

```typescript theme={null}
const triqai = new Triqai("triq_your_api_key", {
  // Base URL (default: https://api.triqai.com)
  baseUrl: "https://api.triqai.com",

  // Retry configuration
  maxRetries: 3,          // default: 3
  retryDelay: 500,        // base delay in ms (default: 500)
  maxRetryDelay: 30_000,  // max delay in ms (default: 30000)

  // Request timeout in ms (default: 60000)
  timeout: 60_000,

  // Extra headers for every request
  defaultHeaders: {
    "X-Custom-Header": "value",
  },

  // Debug hooks
  onRequest: (info) => console.log(`${info.method} ${info.url}`),
  onResponse: (info) => console.log(`${info.status} in ${info.durationMs}ms`),
});
```

## Options Reference

| Option           | Type                     | Default                  | Description                                                   |
| ---------------- | ------------------------ | ------------------------ | ------------------------------------------------------------- |
| `baseUrl`        | `string`                 | `https://api.triqai.com` | API base URL                                                  |
| `maxRetries`     | `number`                 | `3`                      | Maximum number of retry attempts for transient errors         |
| `retryDelay`     | `number`                 | `500`                    | Base delay between retries in milliseconds                    |
| `maxRetryDelay`  | `number`                 | `30000`                  | Maximum delay between retries in milliseconds                 |
| `timeout`        | `number`                 | `60000`                  | Request timeout in milliseconds                               |
| `defaultHeaders` | `Record<string, string>` | `{}`                     | Extra headers sent with every request                         |
| `onRequest`      | `(info) => void`         | —                        | Called before each request with method, URL, and headers      |
| `onResponse`     | `(info) => void`         | —                        | Called after each response with status, duration, and headers |

## Debug Hooks

Use `onRequest` and `onResponse` to log or monitor API calls without modifying your application logic:

```typescript theme={null}
const triqai = new Triqai("triq_your_api_key", {
  onRequest: (info) => {
    console.log(`→ ${info.method} ${info.url}`);
  },
  onResponse: (info) => {
    console.log(`← ${info.status} in ${info.durationMs}ms`);
    // info.headers contains X-RateLimit-* values
  },
});
```

## Environment Variables

A common pattern is to read the API key from an environment variable:

```typescript theme={null}
import Triqai from "triqai";

const triqai = new Triqai(process.env.TRIQAI_API_KEY!);
```

```bash .env theme={null}
TRIQAI_API_KEY=triq_your_api_key_here
```
