Caveman
Framework integrationsOpenAI SDK (TypeScript)

OpenAI SDK (TypeScript)

The OpenAI JavaScript SDK takes a base URL as a single constructor argument. Point it at the gateway and both Chat Completions and the Responses API route through it — no other code changes.

OpenAI SDK (TypeScript)
import OpenAI from "openai";

const client = new OpenAI({
baseURL: "http://127.0.0.1:8787/w/my-service/openai/v1",
apiKey: process.env.OPENAI_API_KEY,
});

// Chat Completions and the Responses API both route through the gateway.
const res = await client.responses.create({
model: "gpt-4.1",
input: "Why is the sky blue?",
});

// Connected to Caveman Cloud? Add gateway auth + BYOK headers:
// defaultHeaders: { "x-cave-api-key": CAVE_API_KEY, "x-cave-upstream-key": OPENAI_API_KEY }

One constructor argument. /w/my-service in the base URL attributes this app's spend — no custom headers.

Local vs. connected

The base URL above is the local proxy default (http://127.0.0.1:8787). Connected or managed use swaps in the cloud gateway URL and adds x-cave-api-key (gateway auth) plus x-cave-upstream-key (your per-request provider key) — the trailing comment in the snippet shows exactly where they go.