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

# Configuration

> Client options for the ReyGrid TypeScript SDK: API key, base URL, headers, timeout, custom fetch, and error hook.

```typescript theme={"system"}
import { ReyGrid } from "reygrid";

const client = new ReyGrid({
  apiKey: "your-api-key",
  baseUrl: "https://reygrid.com/api/v1",
  timeoutMs: 60_000,
  headers: { "X-My-Header": "value" },
});
```

All options are optional.

## Options (`ReyGridConfig`)

| Option | Type | Default | Description |
| - | - | - | - |
| `apiKey` | `string` | — | Sent as `Authorization: Bearer <key>` |
| `baseUrl` | `string` | `https://reygrid.com/api/v1` | API base URL. Trailing slashes are removed |
| `headers` | `Record<string, string>` | `{}` | Extra default headers for every request |
| `timeoutMs` | `number` | `60000` | Request timeout in milliseconds |
| `fetch` | `typeof fetch` | `globalThis.fetch` | Custom fetch implementation |
| `onError` | `(error, context: RequestContext) => void` | — | Hook called for failed requests |

`RequestContext` is `{ method: string; url: string; authenticated: boolean }`.

The SDK sets `Accept` and `Content-Type` to `application/json` unless you override them in `headers`.

The constructor throws if no `fetch` is available (Node.js earlier than 18 without a `fetch` option).

## Custom base URL

```typescript theme={"system"}
const client = new ReyGrid({
  baseUrl: "https://custom-gateway.example.com/reygrid",
  apiKey: "your-api-key",
});
```

## Custom `fetch`

```typescript theme={"system"}
const client = new ReyGrid({
  apiKey: "your-api-key",
  fetch: (url, init) => {
    console.log(init?.method ?? "GET", String(url));
    return fetch(url, init);
  },
});
```

## Logging errors with `onError`

```typescript theme={"system"}
const client = new ReyGrid({
  apiKey: "your-api-key",
  onError: (error, { method, url }) => console.error(`${method} ${url}`, error),
});
```

`onError` is called for network failures and API errors from regular requests. It is not called for errors raised while streaming with `streamChat()`.

## Timeouts

`timeoutMs` aborts the request when it elapses. For `streamChat()` it covers the **entire stream**, so raise it for long responses.

## Low-level requests

`client.request<T>(path, init?)` is public and sends an authenticated request relative to `baseUrl`. Prefer the typed methods.

```typescript theme={"system"}
const res = await client.request<{ success: boolean }>("/ping");
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.