Quickstart
Create an API key, send your first request with cURL, Python, TypeScript or Go, point the OpenAI SDK at Lykia and stream the response.
MarkdownOn this page
This page takes you from a new account to your first response. The Lykia API uses the OpenAI Chat Completions format, so if you have called the OpenAI API before, the requests and responses below will look familiar.
1. Create an API key
- Create an account and set up your company. A project called "Default" is created for you along with it.
- Open that project in the dashboard and create a new key under API keys.
- Copy the key straight away. It starts with
lyk-v1-and is shown once, at creation time. Lykia does not store the key itself, so it cannot show it to you again later.
All examples read the key from the LYKIA_API_KEY environment variable:
export LYKIA_API_KEY="<LYKIA_API_KEY>"2. Add credits, or add your own provider key
Choose one of two ways to pay for requests:
- Add credits. On the Credits page of the dashboard you top up a USD balance for your company and pay on Efespay's secure payment page, which opens in a new tab. Your first top-up also moves the company from the Free plan to Standard, the plan that allows paid models. What gets deducted from the balance: Credits and billing.
- Add your own provider key (BYOK). Under Provider keys in your project, add your own key for a provider such as OpenAI, Anthropic or Google AI Studio. Requests to that provider's models then go out with your key and the provider bills you; this works on the Free plan too. See Bring your own key (BYOK).
A request sent with no credits and no provider key returns 402. Error bodies, and which code comes back when, are described in Errors.
3. Send your first request
The request below sends a single user message to openai/gpt-4o-mini. If you added your own provider key in step 2, use a model from that provider instead (for example anthropic/claude-sonnet-4.5 with an Anthropic key). Model ids take the form author/model; the Models page shows how to list them all.
curl https://api.getlykia.com/v1/chat/completions \
-H "Authorization: Bearer $LYKIA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-4o-mini",
"messages": [
{ "role": "user", "content": "Explain what an AI gateway does in one sentence." }
]
}'import os
import requests
response = requests.post(
"https://api.getlykia.com/v1/chat/completions",
headers={"Authorization": f"Bearer {os.environ['LYKIA_API_KEY']}"},
json={
"model": "openai/gpt-4o-mini",
"messages": [
{"role": "user", "content": "Explain what an AI gateway does in one sentence."}
],
},
timeout=60,
)
response.raise_for_status()
data = response.json()
print(data["choices"][0]["message"]["content"])
print("cost (USD):", data["usage"]["cost"])const response = await fetch("https://api.getlykia.com/v1/chat/completions", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.LYKIA_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "openai/gpt-4o-mini",
messages: [
{ role: "user", content: "Explain what an AI gateway does in one sentence." },
],
}),
});
if (!response.ok) {
throw new Error(`Lykia returned ${response.status}: ${await response.text()}`);
}
const data = await response.json();
console.log(data.choices[0].message.content);
console.log("cost (USD):", data.usage.cost);package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
)
func main() {
payload, _ := json.Marshal(map[string]any{
"model": "openai/gpt-4o-mini",
"messages": []map[string]string{
{"role": "user", "content": "Explain what an AI gateway does in one sentence."},
},
})
req, err := http.NewRequest(http.MethodPost, "https://api.getlykia.com/v1/chat/completions", bytes.NewReader(payload))
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Bearer "+os.Getenv("LYKIA_API_KEY"))
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
if resp.StatusCode != http.StatusOK {
panic(fmt.Sprintf("Lykia returned %d: %s", resp.StatusCode, body))
}
var result struct {
Choices []struct {
Message struct {
Content string `json:"content"`
} `json:"message"`
} `json:"choices"`
Usage struct {
Cost float64 `json:"cost"`
} `json:"usage"`
}
if err := json.Unmarshal(body, &result); err != nil {
panic(err)
}
fmt.Println(result.Choices[0].Message.Content)
fmt.Println("cost (USD):", result.Usage.Cost)
}The response uses the OpenAI format, with a few fields added by Lykia:
{
"id": "gen-1795373724-GNtDgXTt5L42PjqQ",
"object": "chat.completion",
"created": 1795373724,
"model": "openai/gpt-4o-mini",
"provider": "openai",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "An AI gateway sits between your application and model providers, giving you one API to call while it routes, bills and logs each request."
},
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 17,
"completion_tokens": 27,
"total_tokens": 44,
"cost": 0.000019,
"is_byok": false,
"cost_details": {
"upstream_cost": 0.000019,
"platform_fee": 0,
"is_byok": false
},
"prompt_tokens_details": {
"cached_tokens": 0,
"cache_write_tokens": 0
},
"completion_tokens_details": {
"reasoning_tokens": 0
}
},
"system_fingerprint": "fp_560af6e559"
}id: Lykia's id for the request (it starts withgen-). The same id comes back in theX-Generation-Idresponse header. Use it withGET /generationto look up cost and timing details.model: the model that actually served the request.provider: the id of the provider that served the request (for exampleopenai).usage.cost: what this request cost, in USD. If you pay with credits, this is the amount taken from your balance; on a request sent with your own provider key,usage.is_byokistrue.
Use the OpenAI SDK
OpenAI's official SDKs work with Lykia unchanged. When you create the client, set the base URL to https://api.getlykia.com/v1 and the API key to your Lykia key; the rest of your code stays the same. Any model id from the catalog works, and the example below calls an Anthropic model.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.getlykia.com/v1",
api_key=os.environ["LYKIA_API_KEY"],
)
completion = client.chat.completions.create(
model="anthropic/claude-sonnet-4.5",
messages=[{"role": "user", "content": "Write a haiku about load balancers."}],
)
print(completion.choices[0].message.content)import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.getlykia.com/v1",
apiKey: process.env.LYKIA_API_KEY,
});
const completion = await client.chat.completions.create({
model: "anthropic/claude-sonnet-4.5",
messages: [{ role: "user", content: "Write a haiku about load balancers." }],
});
console.log(completion.choices[0].message.content);Stream the response
To receive the answer as it is generated instead of waiting for all of it, add "stream": true to the request. Lykia sends the response as Server-Sent Events, and the SDKs parse the stream for you.
curl -N https://api.getlykia.com/v1/chat/completions \
-H "Authorization: Bearer $LYKIA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "google/gemini-2.5-flash",
"stream": true,
"messages": [{ "role": "user", "content": "Count from 1 to 5, one number per line." }]
}'import os
from openai import OpenAI
client = OpenAI(base_url="https://api.getlykia.com/v1", api_key=os.environ["LYKIA_API_KEY"])
stream = client.chat.completions.create(
model="google/gemini-2.5-flash",
messages=[{"role": "user", "content": "Count from 1 to 5, one number per line."}],
stream=True,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
print()import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.getlykia.com/v1", apiKey: process.env.LYKIA_API_KEY });
const stream = await client.chat.completions.create({
model: "google/gemini-2.5-flash",
messages: [{ role: "user", content: "Count from 1 to 5, one number per line." }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}
process.stdout.write("\n");Usage and cost arrive in the last chunk of the stream. The Streaming guide covers the format and what happens if you stop reading halfway.
Next steps
- How Lykia works: see how projects, keys and credits come together on every request.
- Model fallbacks: move on to the next model automatically when one cannot answer.
- Errors: know which errors to retry and which mean the request needs fixing.
POST /chat/completions: every field of the request body.