The gateway speaks the OpenAI API, so the OpenAI SDK works with a base URL change (gateway quickstart). The opentoken SDK adds fail-open on top: the gateway must accept each call within 1.5 seconds; on a timeout, a connection error or a 5xx the call goes straight to Bedrock in your account, a circuit breaker keeps later calls direct until we're healthy, and direct calls are still measured. A stream that already started is never retried.
Set OT_API_KEY (and OT_INGEST_KEY for traces), then:
import opentoken
opentoken.init(base_url="https://getopentoken.com/v1")
client = opentoken.openai_client() # an openai.OpenAI with fail-open routing; AsyncOpenAI: async_openai_client()
with opentoken.context(feature="onboarding", customer="acme"):
completion = client.chat.completions.create(
model="amazon/nova-lite",
messages=[{"role": "user", "content": "Say hello in one sentence."}],
)
print(completion.choices[0].message.content)Features and customers set with opentoken.context() / withContext() travel to the gateway as X-OT-Feature, X-OT-Customer and X-OT-Run-Id, which budgets and per-run limits key on. The share of traffic that goes through the gateway per feature is set under SDK routing, without a redeploy.