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

# JavaScript SDK

> Connect to Responses and Chat Completions using the official OpenAI SDK.

## Install and configure

```bash theme={null}
npm install openai
export CODEFLARE_API_KEY="YOUR_CODEFLARE_KEY"
```

Copy the [regional Base URL](/en/regions) and [model ID](/en/models). This example requires a Responses-compatible model. JavaScript examples run on the Node.js server, not in a browser.

<CodeGroup>
  ```python Python theme={null}
  from openai import OpenAI
  import os

  client = OpenAI(
      api_key=os.environ["CODEFLARE_API_KEY"],
      base_url="https://YOUR-REGION.example/v1",
      max_retries=0,
  )
  response = client.responses.create(
      model="MODEL_ID", input="Hello",
      max_output_tokens=256, store=False,
  )
  print(response.output_text)
  ```

  ```javascript JavaScript theme={null}
  import OpenAI from "openai";

  const client = new OpenAI({
    apiKey: process.env.CODEFLARE_API_KEY,
    baseURL: "https://YOUR-REGION.example/v1",
    maxRetries: 0,
  });
  const response = await client.responses.create({
    model: "MODEL_ID", input: "Hello",
    max_output_tokens: 256, store: false,
  });
  console.log(response.output_text);
  ```

  ```bash cURL theme={null}
  curl "https://YOUR-REGION.example/v1/responses" \
    -H "Authorization: Bearer $CODEFLARE_API_KEY" \
    -H 'Content-Type: application/json' \
    -d '{"model":"MODEL_ID","input":"Hello","max_output_tokens":256,"store":false}'
  ```
</CodeGroup>

## Stream output

Reuse the configured `client` above with automatic retries disabled and listen for text deltas. Streaming requires a compatible route.

<CodeGroup>
  ```python Python theme={null}
  with client.responses.create(
      model="MODEL_ID", input="Hello",
      max_output_tokens=256, store=False, stream=True,
  ) as stream:
      for event in stream:
          if event.type == "response.output_text.delta":
              print(event.delta, end="", flush=True)
  ```

  ```javascript JavaScript theme={null}
  const stream = await client.responses.create({
    model: "MODEL_ID", input: "Hello",
    max_output_tokens: 256, store: false, stream: true,
  });
  for await (const event of stream) {
    if (event.type === "response.output_text.delta") {
      process.stdout.write(event.delta);
    }
  }
  ```
</CodeGroup>

## Chat Completions

For a `chat-completions` model, use `client.chat.completions.create`. See [Chat Completions](/en/api/chat-completions) for the request and streaming format.

<Warning>Default SDK retries can duplicate generation and charges. Set `max_retries=0` in Python or `maxRetries: 0` in JavaScript, as shown. After an interruption, check request logs and any stored response before submitting another call.</Warning>

The SDK is a client. Actual features and limits depend on the Codeflare model and channel configuration.


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