Docs/Integrations/OpenAI SDK
OpenAI SDK
Change the base URL, add one header — chat completions, responses, embeddings, and streaming all pass through unchanged.
Setup
Requests to /openai/… are forwarded to api.openai.com byte-for-byte. Your OpenAI key stays in Authorization exactly as the SDK sends it; your valite key rides x-valite-api-key.
from openai import OpenAI
client = OpenAI(
api_key="sk-...", # unchanged
base_url="https://gateway.valite.ai/openai/v1",
default_headers={"x-valite-api-key": "vk_..."},
)
resp = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello"}],
)Streaming and tools
Streaming, tool calls, JSON mode, and the Responses API work unchanged — the gateway relays whatever the OpenAI API supports. For streamed requests, valite injects stream_options.include_usage into the forwarded copy so token usage is always metered; the response you receive is not modified.
Note
Workflow attribution
Tag the workflow in the base URL (/openai/wf/<workflow>/v1) or per request:
client.chat.completions.create(
model="gpt-4o",
messages=[...],
extra_headers={"x-valite-workflow": "support-triage"},
)See Workflows & Runs for run grouping via x-valite-run-id or traceparent.