CLAUDE API NODE.JS

Call the Claude API from Node.js and TypeScript.

A Node.js service can call WorldGate's Claude catalogue through the OpenAI JavaScript client. Configure the key on the server, set the WorldGate v1 base URL, and choose a listed Claude identifier. The same pattern works in TypeScript, server routes, workers, and background queues when credentials never reach browser code.

Create an account
01

Install the JavaScript client

Add openai to the server package and commit the lockfile. Use an actively supported Node.js runtime and keep the API client inside server-only modules so bundlers cannot include credentials in frontend output.

02

Fail closed when the key is missing

Read WORLDGATE_API_KEY from process.env and stop application startup when it is empty. Do not silently substitute a development key, echo it in an error response, or expose it through a public runtime configuration object.

03

Configure a Claude model explicitly

Pass https://worldgateapi.com/v1 as baseURL and select a current Claude model identifier. Keep the model in validated server configuration rather than accepting any browser-supplied model string.

04

Stream without leaking resources

When streaming, propagate client cancellation to the upstream request, impose an application timeout, and close readers after disconnects. Buffer only what the product needs instead of retaining complete prompts and responses by default.

05

Use bounded, idempotent retries

Retry transient failures with backoff and jitter. Do not retry invalid 400 payloads, authentication failures, or insufficient-balance responses. For jobs with side effects, ensure a repeated model response cannot perform the side effect twice.

06

Separate keys by service

Give production APIs, queues, previews, and local development distinct WorldGate keys. Apply a hard cap to autonomous workers when required and use usage records to attribute each Node.js service's token cost.

NODE.JS QUICK START

Keep Claude calls in server-only code.

Use a dedicated project key and never expose it through frontend environment variables.

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.WORLDGATE_API_KEY,
  baseURL: "https://worldgateapi.com/v1",
});

const response = await client.chat.completions.create({
  model: "claude-sonnet-5",
  messages: [{ role: "user", content: "Review this TypeScript module." }],
});

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

METHODOLOGY & SOURCES

Review the JavaScript client.

Node.js setup reviewed against WorldGate's deployed chat completions surface on July 31, 2026.

COMMON QUESTIONS

What developers ask

Can Node.js use Claude through the OpenAI package?

Yes. Configure the WorldGate baseURL, WorldGate key, and a Claude model listed in the current catalogue.

Can I put the WorldGate key in Next.js public env?

No. Keep it in a server-only variable and call WorldGate from a route handler or backend service.

Does TypeScript work with this setup?

Yes. The OpenAI JavaScript package includes TypeScript support; validate any dynamic model or message input at your application boundary.

Can Node.js stream WorldGate responses?

Yes. Handle cancellation, timeouts, partial output, and disconnect cleanup explicitly.

How do I control a background worker's spend?

Use a dedicated key, configure a hard cap when needed, enable alerts, and restrict retries and maximum output tokens.

Lower model cost. Clearer usage.

Start with one WorldGate API key.

Start building