npm package: @jelai-ai/sdk
Description: Client SDK for the Jelai AI service with OpenAI-compatible surface
Latest version: 0.1.0

# Jelai SDK

Lightweight TypeScript client that mirrors the OpenAI Chat Completions surface while talking to the Jelai backend (`/api/ai/request`). Use it anywhere you would normally drop in the official OpenAI SDK, swapping `new OpenAI(...)` for `new JelaiClient(...)`.

## Install

```bash
npm install @jelai/sdk
```

This SDK uses Axios under the hood. Provide a custom `axiosInstance` or additional headers/timeouts through the constructor options if required.

## Quick start

```ts
import JelaiClient from '@jelai/sdk';

const client = new JelaiClient({
  apiKey: process.env.AI_LICENSE_KEY!,        // maps to client license key
  baseURL: 'https://api.example.com/api',     // defaults to http://localhost:4000/api
});

const completion = await client.chat.completions.create({
  model: 'model-uuid-or-slug',
  messages: [
    { role: 'system', content: 'You are a helpful assistant.' },
    { role: 'user', content: 'Summarise our latest release notes.' },
  ],
});

console.log(completion.choices[0].message.content);
```

## API

### `new JelaiClient(options)`

| Option         | Type                     | Default                     | Description |
|----------------|--------------------------|-----------------------------|-------------|
| `apiKey`       | `string`                 | **required**                | Maps to the client `licenseKey` stored in the backend. |
| `baseURL`      | `string`                 | `http://localhost:4000/api` | Base URL of your Jelai API (prefix must include `/api`). |
| `axiosInstance`| `AxiosInstance`          | new Axios client            | Provide a preconfigured Axios instance (e.g. for logging, retries). |
| `timeoutMs`    | `number`                 | `30000`                     | Request timeout when using the default Axios instance. |
| `headers`      | `Record<string, string>` | `{}`                        | Default headers applied to every request. |

### `client.chat.completions.create(params)`

Compatible with the OpenAI Chat Completions shape (subset):

| Param          | Type                               | Description |
|----------------|------------------------------------|-------------|
| `model`        | `string`                           | Model identifier assigned to the client in the admin panel. |
| `messages`     | `ChatCompletionMessageParam[]`     | Conversation history. Messages are flattened into a single prompt for the backend. |
| `max_tokens`   | `number` _(optional)_              | Currently advisory only. |
| `temperature`  | `number` _(optional)_              | Currently ignored. |
| `licenseKey`   | `string` _(optional)_              | Override the client license for this call; defaults to the constructor `apiKey`. |

Returns a `ChatCompletion` object with `choices` and `usage` fields shaped like OpenAI responses.

## Error handling

Non-2xx responses throw an `Error` populated with the backend message (if provided). Wrap requests in `try/catch` to inspect failures.

## Building from source

```bash
npm install
npm run build
```

Compiled artifacts emit to `dist/`. Consumers import from the published package; avoid deep-linking to internal files.