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

# Node.js Integration Guide for Boole AI — OpenAI SDK

> Install the openai npm package and make chat, streaming, and tool-call requests to Boole AI from any Node.js or TypeScript application.

Boole AI works with the official OpenAI Node.js SDK. Install it from npm, configure the base URL, and every existing chat, streaming, and tool-call pattern works unchanged — no wrapper library, no extra dependencies, no code restructuring required.

## Installation

<CodeGroup>
  ```bash npm theme={null}
  npm install openai
  ```

  ```bash yarn theme={null}
  yarn add openai
  ```

  ```bash pnpm theme={null}
  pnpm add openai
  ```
</CodeGroup>

<Tip>
  Use `process.env.BOOLE_API_KEY` to read your API key at runtime — never hardcode it in source files. Set the variable in your shell, a `.env` file loaded with `dotenv`, or your deployment platform's secret manager.
</Tip>

## Basic Chat Completion

Instantiate the client with Boole's `baseURL` and call `chat.completions.create` exactly as you would against the OpenAI API.

```javascript example.mjs theme={null}
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.boole.dev/v1",
  apiKey: process.env.BOOLE_API_KEY,
});

const response = await client.chat.completions.create({
  model: "llama-3.3-70b-instruct",
  messages: [
    { role: "system", content: "You are a helpful assistant." },
    { role: "user", content: "What is the capital of France?" },
  ],
});

console.log(response.choices[0].message.content);
```

## Streaming

Set `stream: true` and iterate over the response with `for await`. Boole begins returning tokens almost immediately at up to 312 tokens/sec on Llama 3.3 70B.

```javascript streaming.mjs theme={null}
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.boole.dev/v1",
  apiKey: process.env.BOOLE_API_KEY,
});

const stream = await client.chat.completions.create({
  model: "llama-3.3-70b-instruct",
  messages: [{ role: "user", content: "Write a short poem about the ocean." }],
  stream: true,
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content || "");
}
```

## TypeScript

The OpenAI SDK ships with full TypeScript definitions. Import `ChatCompletionMessageParam` and other types directly from the `openai/resources` sub-path — no extra `@types` package needed.

```typescript example.ts theme={null}
import OpenAI from "openai";
import type { ChatCompletionMessageParam } from "openai/resources/chat";

const client = new OpenAI({
  baseURL: "https://api.boole.dev/v1",
  apiKey: process.env.BOOLE_API_KEY!,
});

const messages: ChatCompletionMessageParam[] = [
  { role: "user", content: "Hello!" },
];

const response = await client.chat.completions.create({
  model: "llama-3.3-70b-instruct",
  messages,
});

console.log(response.choices[0].message.content);
```

## Local Deployment

When running the Boole local binary, change `baseURL` to point at `localhost`. The local server does not validate API keys, so pass any non-empty string.

```javascript local.mjs theme={null}
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "http://localhost:8000/v1",
  apiKey: "local",                  // any non-empty string
});

const response = await client.chat.completions.create({
  model: "llama-3.3-70b-instruct",
  messages: [{ role: "user", content: "Hello from my local GPU!" }],
});

console.log(response.choices[0].message.content);
```

<Info>
  The local binary cold-starts in under 400 ms and exposes the same `/v1` interface as the cloud API. Toggle between environments by changing a single line — the rest of your application code is unchanged.
</Info>
