---
title: "OpenAI JavaScript SDK"
description: "Run the exact JavaScript source exercised by the Nexus Node and Cloudflare compatibility suite."
---

> Documentation Index
> Fetch the complete documentation index at: https://nexus.microvoid.io/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAI JavaScript SDK

## Outcome

OpenAI JavaScript SDK 只替换 Nexus Base URL 和 Inference Key，原始 `model`、消息和 Provider 参数保持不变。

## Install


```sh title="Terminal"
npm install openai@6.48.0
```


## Configure

将 Fixture 值替换为应用交付的 Base URL、Inference Key 和上游模型名：


```sh title="Terminal"
export NEXUS_BASE_URL="https://gateway.nexus.microvoid.io/providers/00000000-0000-0000-0000-000000000141"
export NEXUS_API_KEY="<NEXUS_INFERENCE_KEY>"
export NEXUS_MODEL="provider/opaque-model-v9"
```


## Run


```js title="openai-javascript.mjs"
import OpenAI from 'openai';

function requiredEnvironment(name) {
  const value = process.env[name]?.trim();
  if (!value) throw new Error(`${name} is required`);
  return value;
}

const client = new OpenAI({
  baseURL: requiredEnvironment('NEXUS_BASE_URL'),
  apiKey: requiredEnvironment('NEXUS_API_KEY'),
  maxRetries: 0,
});

const completion = await client.chat.completions.create({
  model: requiredEnvironment('NEXUS_MODEL'),
  messages: [{ role: 'user', content: 'Keep this request unchanged.' }],
  temperature: 0.37,
});

console.log(
  JSON.stringify({
    model: completion.model,
    content: completion.choices[0]?.message.content,
  }),
);
```


```sh title="Terminal"
node openai-javascript.mjs
```

## Check your work

输出应包含 Provider 返回的 `model` 和正文。保存响应头中的 `x-nexus-request-id`，并让平台方在 Usage 中确认同一 WorkspaceAccess 和 ProviderConnection。

> **Executable source**
>
> 代码块由 `tests/e2e/examples/openai-javascript.mjs` 生成；Node 与 Cloudflare E2E 均通过本地 Fake Provider 执行该文件。

Source: https://nexus.microvoid.io/docs/make-model-requests/openai-javascript/index.mdx
