API reference
The base URL, authentication header, versioning, app attribution and response headers, and every endpoint of the Lykia API.
MarkdownThe Lykia API is an OpenAI-compatible REST API. Request and response bodies are JSON, and streamed responses arrive as Server-Sent Events. This section documents each endpoint field by field; for concepts and walkthroughs, start with the Guides.
Base URL
All endpoint paths are relative to:
https://api.getlykia.com/v1So a POST /chat/completions request goes to https://api.getlykia.com/v1/chat/completions.
Authentication
Send your project's API key in the Authorization header of every request:
Authorization: Bearer <LYKIA_API_KEY>Keys start with lyk-v1- and belong to exactly one project, so each request is handled with that project's settings, budget and logs. A missing, invalid, disabled, archived or expired key gets a 401; a key whose project has been archived gets a 403. Creating keys, spending limits and storing keys safely are covered in Authentication and API keys.
Requests with a body send JSON with Content-Type: application/json. The body has a size limit set by Lykia; a larger body gets 413. Each key also has a per-minute request limit; see Limits.
Versioning
The version is part of the base URL (/v1), and this reference describes v1. New fields may show up in responses over time, so write your client to ignore fields it does not recognise; that way additions never break it.
App attribution headers
Two optional headers tell Lykia which application sent a request:
| Header | Meaning |
|---|---|
HTTP-Referer | Your application's URL, for example https://example.com |
X-Title | Your application's display name, for example Example Support Bot |
Lykia stores both values with the request record. When several apps share a project, this is how you tell their traffic apart in the logs and in the app field of GET /generation. Leaving them out has no effect on the request itself.
curl https://api.getlykia.com/v1/chat/completions \
-H "Authorization: Bearer $LYKIA_API_KEY" \
-H "Content-Type: application/json" \
-H "HTTP-Referer: https://example.com" \
-H "X-Title: Example Support Bot" \
-d '{
"model": "openai/gpt-4o-mini",
"messages": [{ "role": "user", "content": "Hello!" }]
}'import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.getlykia.com/v1",
api_key=os.environ["LYKIA_API_KEY"],
default_headers={
"HTTP-Referer": "https://example.com",
"X-Title": "Example Support Bot",
},
)
completion = client.chat.completions.create(
model="openai/gpt-4o-mini",
messages=[{"role": "user", "content": "Hello!"}],
)
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,
defaultHeaders: {
"HTTP-Referer": "https://example.com",
"X-Title": "Example Support Bot",
},
});
const completion = await client.chat.completions.create({
model: "openai/gpt-4o-mini",
messages: [{ role: "user", content: "Hello!" }],
});
console.log(completion.choices[0].message.content);Errors
A failed request returns an HTTP status code and a body like this:
{
"error": {
"message": "Insufficient credits. Add credits to your balance, or add your own provider key (BYOK) to this project.",
"type": "invalid_request_error",
"code": "insufficient_credits",
"status": 402,
"metadata": {
"reason": "insufficient_credits"
}
}
}message: a human-readable explanation in English. Don't branch on its wording.type: the OpenAI-style error type, such asinvalid_request_error,authentication_errororrate_limit_error.code: a stable machine code as a string, such asinsufficient_credits,invalid_api_keyorpreset_not_found. Branch on this.status: the HTTP status code as a number.metadata: always hasreason, the stable error class (invalid_request,unauthorized,insufficient_credits…);providerwhen a provider caused the error, andretry_afterin seconds when it is worth waiting.
Every status code, and which ones are worth retrying, is listed under Errors.
Response headers
| Header | When | Meaning |
|---|---|---|
X-Generation-Id | Every response, including errors and early rejections such as 401, 413, 429 and an invalid body | An id for the request. On POST /chat/completions it is the same as the id field of the response. A record you can fetch with GET /generation exists only for requests that reached a provider. |
X-Max-Tokens-Applied | POST /chat/completions, when Lykia set or lowered the output limit | The output limit Lykia sent to the provider, so that the request's cost fits what is available. See Output limit. |
X-Lykia-Cost | Image, speech and transcription responses, and the content of a completed video | The request's cost in USD, the same as usage.cost. |
X-Lykia-Preset | POST /chat/completions, POST /embeddings and the media endpoints, when model was a preset (@name) | The preset's name. The response's model field is the real model. See Model presets. |
X-Lykia-Reasoning | POST /chat/completions, value dropped | Lykia turned thinking off for this request because an assistant message in a tool loop came back without its reasoning_details. See Reasoning and prompt caching. |
Retry-After | 429 from the per-key rate limit | Seconds to wait before sending again. |
Responses are sent with Cache-Control: no-store. The API answers cross-origin requests from any origin and exposes the headers above to browser code, but keep API keys out of browsers: send requests from your own server.