Python SDK
Python SDK
Orqen works with the Python SDK you already use — Anthropic SDK, OpenAI SDK, or AWS Bedrock (boto3). For LLM calls you use the standard openai package pointed at Orqen's endpoint. A dedicated management SDK for programmatic key and usage management is coming soon.
LLM calls: use the OpenAI SDK
Install the standard OpenAI package. No additional package required.
pip install openaifrom openai import OpenAI
client = OpenAI(
api_key="sk-orq-YOUR_KEY", # Your Orqen key
base_url="https://api.orqen.app/v1", # Orqen endpoint
)
response = client.chat.completions.create(
model="gpt-4o", # or "orqen/auto" to let Orqen choose
messages=[{"role": "user", "content": "What is the weather in London?"}],
tools=[...], # Orqen optimizes the request automatically
)
print(response.choices[0].message.content)Prompt compression & session tracking
Orqen automatically deduplicates redundant content (empty turns, AI preamble filler, duplicate messages) on every request — no configuration needed. To group a conversation's turns into a session visible in the dashboard Sessions page, pass the X-Orqen-Session-Id header with any string identifier.
from openai import OpenAI
client = OpenAI(
api_key="sk-orq-YOUR_KEY",
base_url="https://api.orqen.app/v1",
default_headers={"X-Orqen-Session-Id": "my-session-abc"},
)Other frameworks
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="gpt-4o",
api_key="sk-orq-YOUR_KEY",
base_url="https://api.orqen.app/v1",
)Account management via REST
Until the native SDK ships, use httpx or requests to call the management API. All endpoints accept your Orqen key as a Bearer token.
import httpx
ORQEN_KEY = "sk-orq-YOUR_KEY"
BASE = "https://api.orqen.app"
def orqen(method: str, path: str, **kwargs):
with httpx.Client() as client:
r = client.request(
method, BASE + path,
headers={"Authorization": f"Bearer {ORQEN_KEY}"},
**kwargs,
)
r.raise_for_status()
return r.json() if r.content else None
# Current month usage
summary = orqen("GET", "/v1/account/usage/summary")
print(f"Tokens saved: {summary['tokens_saved_estimate']:,}")
print(f"Provider savings: {summary['provider_savings_usd']:.3f{'}'}")
# Create an API key
new_key = orqen("POST", "/v1/account/keys", json={
"name": "ci-agent",
})
print(f"New key: {new_key['key']}") # shown once
# Add a provider key
orqen("PUT", "/v1/account/providers", json={"provider": "openai", "api_key": "sk-proj-..."})
# Set routing mode
orqen("PUT", "/v1/account/routing/preferences", json={"routing_mode": "auto"})Native Python management SDK
A first-class pip install orqen package is in development with typed responses and full IDE autocomplete.
# Coming soon — pip install orqen
from orqen import OrqenClient
client = OrqenClient(api_key="sk-orq-...")
summary = client.usage.summary()
new_key = client.keys.create(name="production-agent")
client.providers.save(provider="openai", api_key="sk-proj-...")
client.routing.update(routing_mode="auto")