Skip to content

Migrating from OpenAI

What to change when moving code that calls the OpenAI API over to Lykia; usually the base URL, the API key and the model id are enough.

Markdown
On this page

The Lykia API follows the OpenAI Chat Completions format. When you move an application that uses the OpenAI SDK or plain HTTP requests, your business logic stays as it is. What changes is where the client connects, which key it sends and how model names are written.

The three changes

  1. Base URL: https://api.getlykia.com/v1
  2. API key: your Lykia API key (lyk-v1-…) instead of the OpenAI key. The Quickstart shows how to create one.
  3. Model id: Lykia writes models as author/model. gpt-4o becomes openai/gpt-4o, and gpt-4o-mini becomes openai/gpt-4o-mini.
import os

from openai import OpenAI

client = OpenAI(
    base_url="https://api.getlykia.com/v1",  # was: the default OpenAI endpoint
    api_key=os.environ["LYKIA_API_KEY"],  # was: OPENAI_API_KEY
)

completion = client.chat.completions.create(
    model="openai/gpt-4o",  # was: "gpt-4o"
    messages=[{"role": "user", "content": "Translate 'good morning' into Turkish."}],
)
print(completion.choices[0].message.content)
print("served by:", completion.model_extra.get("provider"), "cost (USD):", getattr(completion.usage, "cost", None))

If your code creates the client without options, the official OpenAI SDKs read the base URL and the key from environment variables. In that case you can switch to Lykia without touching the code, apart from updating the model ids:

Terminal
# The official OpenAI SDKs read these variables when no explicit options are passed.
export OPENAI_BASE_URL="https://api.getlykia.com/v1"
export OPENAI_API_KEY="$LYKIA_API_KEY"

What stays the same

  • The request body: messages, temperature, max_tokens, tools, response_format, stream and the other fields keep their names, though a few are not passed on (see Before you switch). Which models honour a field is listed in their supported_parameters in the catalog.
  • The response shape: choices, message, finish_reason and usage are where you expect them.
  • Streaming: Server-Sent Events, chat.completion.chunk objects and data: [DONE]. See Streaming.
  • SDK error types: Lykia errors use OpenAI's error body shape, so the SDK raises them the same way. Status codes are listed in Errors.

Fields Lykia adds

Responses carry a few fields OpenAI does not send. You do not have to use them, and existing code simply ignores them.

  • provider: the id of the provider that served the request (for example openai).
  • usage.cost: what the request cost, in USD; usage.is_byok: whether your own provider key was used; usage.prompt_tokens_details.cache_write_tokens: input tokens written to the cache.
  • id: starts with gen-, and comes back in the X-Generation-Id response header too. Pass it to GET /generation for cost and timing details.

There are extra request fields too: models for model fallbacks and provider for provider preferences. The SDKs do not know these fields, so send them through extra_body in Python, or add them to the body in TypeScript.

Identify your application

The optional HTTP-Referer and X-Title headers carry the URL and name of the application sending the request. Lykia stores them in the request log, which helps you tell apps apart when several share a project. They are not forwarded to providers.

cURL
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!" }]
  }'

Before you switch

  • Endpoints you call. Lykia's first release offers the endpoints in the API reference: chat completions, plus lookups for the catalog, your key, credits and request records. If your code calls other OpenAI endpoints, keep those calls on your current provider for now.
  • Request fields that are not passed on. On requests that go out with Lykia's keys, Lykia passes on only a fixed list of body fields and drops the rest without an error. Among the dropped fields are n (you get a single choice), service_tier, store, prediction, modalities and audio (no audio output). user and metadata are Lykia's request tags: they are stored with the record for usage breakdowns and never sent to OpenAI (Tags and usage breakdown). The full list is in What is sent to the provider. Requests with your own OpenAI key as a provider key are passed on in full.
  • max_tokens. Lykia may set or lower the output limit so that the request's cost fits the available balance, key limit or project budget, and reports the value in the X-Max-Tokens-Applied header. See Output limit.
  • Model ids. Look up the catalog id of every OpenAI model you use with GET /models. The catalog also lists models from other authors, so the same code can try them.
  • Paying. Paid models need a credit balance on your company. If you would rather keep using your OpenAI key, add it to the project as a provider key: requests to OpenAI models then go out with that key and OpenAI bills you. See Bring your own key (BYOK).
  • Privacy. By default Lykia does not store prompt or response text. Details in Privacy and logging.

Next steps