Docs
Yantra speaks the OpenAI API. If your code talks to OpenAI today, it talks to Yantra with two edits.
1 · Base URL & key
Set your gateway base URL and your yk_live_… key. Everything else is standard OpenAI.
Base URLhttps://api.aitklabs.in/v1
Auth headerAuthorization: Bearer yk_live_…
2 · Python (OpenAI SDK)
from openai import OpenAI
client = OpenAI(
base_url="https://api.aitklabs.in/v1",
api_key="yk_live_xxxxxxxxxxxx", # your single Yantra key
)
resp = client.chat.completions.create(
model="auto:cheap", # or "openai/gpt-4o", "anthropic/claude-sonnet-4-6", …
messages=[{"role": "user", "content": "Hello from Yantra!"}],
)
print(resp.choices[0].message.content)
print(resp.yantra) # which model/provider we routed to + ₹ cost3 · cURL
curl https://api.aitklabs.in/v1/chat/completions \
-H "Authorization: Bearer yk_live_xxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "auto:reasoning",
"messages": [{"role":"user","content":"Prove sqrt(2) is irrational."}]
}'Routing modes
openai/gpt-4oExplicit — route to exactly this model
autoBalanced default pick
auto:cheapCheapest capable model
auto:fastLowest-latency model
auto:reasoningStrong step-by-step reasoning
auto:long-contextLargest context window
If the chosen provider returns a retryable error (429/5xx/timeout), Yantra automatically fails over to a sibling model of the same class and tells you via x-yantra-fell-back.
Response headers
x-yantra-routed-toFinal model id
x-yantra-providerProvider that served it
x-yantra-cost-paiseCharge for this request (paise)
x-yantra-balance-paiseRemaining balance (paise)
x-yantra-fell-backtrue if failover occurred
Error codes
401Missing or invalid API key
402Insufficient credit — top up over UPI
404Unknown model id
429Rate limited (provider) — auto-retried
502All providers in the class failed