VanaAPI

← Escritos

Setting baseURL in the OpenAI Node SDK

Formatos de comunicaciónEN2026-10-25

To connect the OpenAI Node SDK to another compatible service, configure its baseURL option. This changes the destination for requests without requiring you to replace the SDK. The option belongs in the client constructor, alongside your API key, rather than inside a chat request. ([github.com](https://github.com/openai/openai-node/blob/main/src/client.ts?utm_source=openai))

This walkthrough uses Vana API. Its OpenAI-compatible interface uses the api.vanaapi.com host with /v1 appended. That path matters: the service also exposes other protocol interfaces, but this example uses the OpenAI request format throughout. ([vanaapi.com](https://vanaapi.com/plug-in?locale=en))

§ 1. Install the Node SDK

In your Node.js project directory, run the following command. The official JavaScript and TypeScript SDK is distributed as the openai package. ([platform.openai.com](https://platform.openai.com/docs/quickstart))

 1  npm install openai

Create a file named example.mjs for the walkthrough. Keep this test separate from your application’s existing client configuration so you can verify the connection before changing production code.

§ 2. Prepare your credentials

Create a Vana API account to obtain your API key. Keep the key in your server environment rather than embedding it in source code. The SDK documentation recommends keeping credentials on a trusted server because browser-side credentials can be extracted. ([github.com](https://github.com/openai/openai-node/blob/main/docs/authentication.md?utm_source=openai))

For this example, use an environment variable named VANA_API_KEY. In a macOS or Linux terminal, set it before running your script:

 1  export VANA_API_KEY='your-vana-api-key'

The variable name is an application convention here. Because it is not the SDK’s default credential variable, the next step passes its value explicitly.

§ 3. Set baseURL in the constructor

Add the following JavaScript to example.mjs. Notice the exact capitalization: baseURL, not baseUrl or base_url. The SDK accepts this constructor option and uses it instead of its default API address. ([github.com](https://github.com/openai/openai-node/blob/main/src/client.ts?utm_source=openai))

 1  import OpenAI from 'openai';
 2  const apiKey = process.env.VANA_API_KEY;

if (!apiKey) throw new Error('Set VANA_API_KEY before running this script.');

 1  const client = new OpenAI({ apiKey, baseURL: 'https://api.vanaapi.com/v1' });

Use the API root, not the complete chat-completions address. Vana documents /v1 as the OpenAI-compatible base path and /v1/chat/completions as the chat endpoint; the SDK supplies the resource path when you call its chat method. ([vanaapi.com](https://vanaapi.com/plug-in?locale=en))

§ 4. Send a small test request

Append the following statements to the same file. Set VANA_MODEL_ID in your environment to the exact API identifier supplied by Vana for your selected model. For example, choose GPT-6.1 Sol and copy its API identifier from the service documentation rather than assuming its display name is the request value. ([vanaapi.com](https://vanaapi.com/plug-in?locale=en))

 1  const model = process.env.VANA_MODEL_ID;

if (!model) throw new Error('Set VANA_MODEL_ID before running this script.');

 1  const completion = await client.chat.completions.create({ model, messages: [{ role: 'user', content: 'Reply with one short sentence.' }] });
 2  console.log(completion.choices[0]?.message.content);

Run node example.mjs. Start with this minimal request before adding streaming, tools, or application-specific parameters. It gives you a smaller configuration to inspect if the request fails.

§ 5. Use environment-only configuration if preferred

The SDK also reads OPENAI_BASE_URL and OPENAI_API_KEY as defaults. If you prefer deployment configuration over explicit constructor values, set both variables and instantiate the client with new OpenAI(). Explicit constructor options take precedence over their corresponding environment defaults. ([github.com](https://github.com/openai/openai-node/blob/main/docs/configuration.md?utm_source=openai))

 1  export OPENAI_BASE_URL='https://api.vanaapi.com/v1'
 2  export OPENAI_API_KEY='your-vana-api-key'

Choose one configuration approach for this test. Avoid leaving an explicit baseURL in your constructor while expecting a different environment value to control the destination.

§ 6. Check the configuration before expanding

  • Destination: Inspect client.baseURL and confirm that it contains the intended host and /v1 path. Never print the API key. ([github.com](https://github.com/openai/openai-node/blob/main/src/client.ts?utm_source=openai))
  • Credentials: Confirm that the environment variable used by your constructor contains the Vana key.
  • Resource path: Keep /chat/completions out of baseURL; select that resource through the SDK method. ([vanaapi.com](https://vanaapi.com/plug-in?locale=en))
  • Next step: Once the minimal request succeeds, move the verified client configuration into your application’s shared API module.