Skip to content

API reference

The base URL, authentication header, versioning, app attribution and response headers, and every endpoint of the Lykia API.

Markdown
On this page

The 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:

text
https://api.getlykia.com/v1

So 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:

http
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:

HeaderMeaning
HTTP-RefererYour application's URL, for example https://example.com
X-TitleYour 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!" }]
  }'

Errors

A failed request returns an HTTP status code and a body like this:

402 Payment Required
{
  "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 as invalid_request_error, authentication_error or rate_limit_error.
  • code: a stable machine code as a string, such as insufficient_credits, invalid_api_key or preset_not_found. Branch on this.
  • status: the HTTP status code as a number.
  • metadata: always has reason, the stable error class (invalid_request, unauthorized, insufficient_credits…); provider when a provider caused the error, and retry_after in seconds when it is worth waiting.

Every status code, and which ones are worth retrying, is listed under Errors.

Response headers

HeaderWhenMeaning
X-Generation-IdEvery response, including errors and early rejections such as 401, 413, 429 and an invalid bodyAn 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-AppliedPOST /chat/completions, when Lykia set or lowered the output limitThe output limit Lykia sent to the provider, so that the request's cost fits what is available. See Output limit.
X-Lykia-CostImage, speech and transcription responses, and the content of a completed videoThe request's cost in USD, the same as usage.cost.
X-Lykia-PresetPOST /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-ReasoningPOST /chat/completions, value droppedLykia 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-After429 from the per-key rate limitSeconds 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.

Endpoints