OpenAI SDK (Python)
The OpenAI Python 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.
import os
from openai import OpenAI
client = OpenAI(
base_url="http://127.0.0.1:8787/w/my-service/openai/v1",
api_key=os.environ["OPENAI_API_KEY"],
)
# Chat Completions and the Responses API both route through the gateway.
res = client.responses.create(model="gpt-4.1", input="Why is the sky blue?")
# Connected to Caveman Cloud? Add gateway auth + BYOK headers:
# default_headers={"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.