QUICKSTART
Make your first request
LightSwitch exposes an OpenAI-compatible interface. Install the official SDK, then change the API key and base URL.
Using Cherry Studio, Cline, or Codex? Open the API / agent guidesStep 1
Create an API key
Step 2
Install the SDK
Step 3
Send a request
from openai import OpenAI
client = OpenAI(
api_key="sk-xxx",
base_url="https://api.lightswitch.app/v1"
)
response = client.chat.completions.create(
model="deepseek-chat",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
],
temperature=0.7,
max_tokens=1024
)
print(response.choices[0].message.content)Authentication
Send your API key as a Bearer token with every request. The full key is shown only once at creation, so store it in a secret manager.
Authorization: Bearer sk-xxxList available models
The model list reflects the providers and pricing currently enabled for your account.
curl https://api.lightswitch.app/v1/models \
-H "Authorization: Bearer sk-xxx"Streaming responses
Set stream=true to receive incremental content over SSE in the same format expected by the OpenAI SDK.
stream = client.chat.completions.create(
model="gpt-4.1-mini",
messages=[{"role": "user", "content": "Explain SSE"}],
stream=True,
)
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="")Tool calling
The tools and tool_choice parameters are forwarded to providers that support function calling.
Deep thinking
Set reasoning_effort on models marked with the reasoning capability. Reasoning tokens count as output usage; the dashboard stores only the final answer, not private chain-of-thought.
response = client.chat.completions.create(
model="gpt-5.6",
messages=[{"role": "user", "content": "Analyze this carefully"}],
reasoning_effort="high",
)Image generation
Use the OpenAI Images SDK with an enabled image model. Size, quality, format, and count are limited to administrator-priced tiers; results are returned as b64_json.
image = client.images.generate(
model="gpt-image-2",
prompt="A clean product photograph of a teal keyboard",
size="1024x1024",
quality="medium",
response_format="b64_json",
)Errors and retries
| Code | Meaning |
|---|---|
| 400 | Invalid request |
| 401 | Invalid or disabled API key |
| 402 | Insufficient balance |
| 429 | Rate or spend limit exceeded |
| 502 | All providers temporarily unavailable |