# 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.

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.

> **Warning:** **Before you start:** a request can only be served if one of these is in place: a credit balance on your company, or your own key for the model's provider (BYOK) added to your project. With neither, the gateway rejects the request with `402`. A new company starts with a zero balance, so complete step 2 below before you send your first request.

## 1. Create an API key

1. [Create an account](https://www.getlykia.com/en/account/register) and set up your company. A project called "Default" is created for you along with it.
2. Open that project in the dashboard and create a new key under **API keys**.
3. 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:

```bash
export LYKIA_API_KEY="<LYKIA_API_KEY>"
```

> **Warning:** Never put an API key in code that runs in a browser, in a mobile app or in a repository. Send requests from your own server. More in [Authentication and API keys](https://www.getlykia.com/en/docs/guides/authentication).

## 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](https://www.getlykia.com/en/app) 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](https://www.getlykia.com/en/docs/guides/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)](https://www.getlykia.com/en/docs/guides/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](https://www.getlykia.com/en/docs/guides/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](https://www.getlykia.com/en/docs/models) page shows how to list them all.

**cURL**

```bash
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." }
    ]
  }'
```

**Python**

```python
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"])
```

**TypeScript**

```typescript
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);
```

**Go**

```go
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:

```json
{
  "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 with `gen-`). The same id comes back in the `X-Generation-Id` response header. Use it with [`GET /generation`](https://www.getlykia.com/en/docs/api-reference/generation) to 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 example `openai`).
- `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_byok` is `true`.

## 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.

**Python**

```python
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)
```

**TypeScript**

```typescript
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);
```

> **Tip:** Other OpenAI-compatible libraries that let you change the base URL connect to Lykia with the same two settings: the base URL and the API key.

## 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**

```bash
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." }]
  }'
```

**Python**

```python
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()
```

**TypeScript**

```typescript
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](https://www.getlykia.com/en/docs/guides/streaming) guide covers the format and what happens if you stop reading halfway.

## Next steps

- [How Lykia works](https://www.getlykia.com/en/docs/how-it-works): see how projects, keys and credits come together on every request.
- [Model fallbacks](https://www.getlykia.com/en/docs/guides/model-fallbacks): move on to the next model automatically when one cannot answer.
- [Errors](https://www.getlykia.com/en/docs/guides/errors): know which errors to retry and which mean the request needs fixing.
- [`POST /chat/completions`](https://www.getlykia.com/en/docs/api-reference/chat-completions): every field of the request body.
