# JavaScript

Use the OpenAI JavaScript SDK with an explicit ohgrok base URL.

<a id="install"></a>

## Install and configure

Run this example on your backend or local machine. Set OHGROK_API_KEY first. JavaScript uses Node.js and an ES module (.mjs).

```
npm install openai
export OHGROK_API_KEY='YOUR_API_KEY'
```

<a id="request"></a>

## Request example

SDK examples cover text chat. Follow the dedicated endpoints for images and video.

```
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.OHGROK_API_KEY,
  baseURL: "https://api.ohgrok.com/v1",
  maxRetries: 0,
});
const response = await client.chat.completions.create({
  model: "grok-4.5",
  messages: [{ role: "user", content: "Hello, ohgrok!" }],
});
console.log(response.choices[0].message.content);
```

<a id="result"></a>

## Read the result and handle failures

Read choices[0].message.content. Keep usage when present. SDK retries are disabled here so a beginner can inspect the first error before sending another request. Enable bounded retries only after reviewing the operation and billing behavior.

- [Error handling](/docs/errors/)
- [Official SDK source](https://github.com/openai/openai-node)

