# Your first model call

Source: https://platform.lyrouter.com/ai_gateway/docs/quickstart/en
Last updated: 2026-10-19

Call LYRouter using an OpenAI-compatible client, then check the response and request log.

## Prepare credentials

Use your personal account's default workspace, or an authorized shared workspace.

### Create and save an API Key

Select **API Keys** in your workspace's left navigation to open the key list. Click **Create API Key** in the upper right and complete the configuration.

(Screenshot: API Keys web page, showing the selected left navigation entry, key list and Create API Key button in the upper right)

Copy the full key from the creation confirmation dialog, save it securely, then confirm that you have saved it. The plaintext key is shown only once.

(Screenshot: API Key creation confirmation, showing the one-time key warning, Copy button and saved-key checkbox)

### Choose a model and copy its identifier

Choose an enabled model with a valid service source in your workspace's model marketplace. Use the copy icon beside its system model identifier, then replace `MODEL_ID` in the examples below.

(Screenshot: Workspace model marketplace, showing enabled models, model identifier copy buttons and service sources)

## Prepare your environment

Choose your operating system and install the tools for your preferred calling method. cURL calls only need cURL; Python and Node.js calls also need their runtime and SDK. Check existing tools before installing them again.

**Choose your operating system**

Windows:
Run these commands in **PowerShell** on Windows 10 / 11.

#### 1. Prepare cURL

Windows 10 / 11 normally includes cURL. Check it first:

```powershell
curl.exe --version
```

If the command is unavailable, install it with WinGet, then reopen the terminal:

```powershell
winget install --id cURL.cURL --exact --source winget
```

Use `curl.exe` to avoid the `curl` alias in Windows PowerShell. If WinGet is unavailable, install [App Installer](https://learn.microsoft.com/windows/package-manager/winget/), or download [cURL](https://curl.se/windows/) and add its extracted `bin` directory to your user PATH.

#### 2. Install Python and its SDK (for Python calls)

```powershell
winget install --id Python.Python.3.14 --exact --source winget
```

Reopen PowerShell after installation. In your example project directory, run:

```powershell
python --version
python -m venv .venv
.\.venv\Scripts\python.exe -m pip install openai
```

Save the Python example below as `example.py` and run `.\.venv\Scripts\python.exe example.py`. Using the virtual environment's executable directly avoids changes to PowerShell's script execution policy.

#### 3. Install Node.js and its SDK (for Node.js calls)

Install Node.js LTS, which includes npm:

```powershell
winget install --id OpenJS.NodeJS.LTS --exact --source winget
```

Reopen PowerShell. In your example project directory, run the following commands; skip initialization if you already have `package.json`:

```powershell
node --version
npm.cmd --version
npm.cmd init -y
npm.cmd install openai
```

Save the Node.js example as `example.mjs` and run `node example.mjs`. Using `npm.cmd` avoids execution policy restrictions on `npm.ps1`. Without WinGet, use the official [Python](https://www.python.org/downloads/windows/) and [Node.js LTS](https://nodejs.org/en/download) installers instead.

#### 4. Set environment variables for this terminal

```powershell
$env:LYROUTER_API_KEY="YOUR_LYROUTER_API_KEY"
$env:LYROUTER_BASE_URL="https://api.lyrouter.com"
```

Linux:
Run these commands in **Bash**. System package installation requires `sudo`; use the commands for your distribution.

#### 1. Install cURL and Python

Ubuntu / Debian:

```bash
sudo apt update
sudo apt install -y curl python3 python3-pip python3-venv
```

Fedora / Rocky Linux:

```bash
sudo dnf install -y curl python3 python3-pip
```

```bash
curl --version
python3 --version
```

For cURL-only calls, install just `curl`.

#### 2. Install the Python SDK (for Python calls)

Create and activate a virtual environment in your example project directory:

```bash
python3 -m venv .venv
source .venv/bin/activate
python -m pip install openai
```

Save the Python example as `example.py` and run `python example.py` in the activated environment.

#### 3. Install Node.js and its SDK (for Node.js calls)

Use [nvm](https://github.com/nvm-sh/nvm#installing-and-updating) to install Node.js LTS rather than an older distribution package. Skip the installer if nvm is already installed:

```bash
curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.8/install.sh | bash
```

Reopen your terminal, then run:

```bash
nvm install --lts
nvm use --lts
node --version
npm --version
```

In your example project directory, install the SDK; skip initialization if `package.json` already exists:

```bash
npm init -y
npm install openai
```

Save the Node.js example as `example.mjs` and run `node example.mjs`. This installation path targets common glibc distributions. For Alpine and other environments, select an appropriate method on the [Node.js download page](https://nodejs.org/en/download).

#### 4. Set environment variables for this terminal

```bash
export LYROUTER_API_KEY="YOUR_LYROUTER_API_KEY"
export LYROUTER_BASE_URL="https://api.lyrouter.com"
```

macOS:
Open **Terminal**. These commands work in Bash / Zsh.

#### 1. Prepare cURL and Homebrew

macOS includes cURL. Check the installed version:

```bash
curl --version
```

Use [Homebrew](https://brew.sh/) to install Python and Node.js. If needed, install Homebrew with its official command and follow the installer's **Next steps** to configure PATH:

```bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
```

To install a newer cURL separately, run `brew install curl`. It is keg-only; follow `brew info curl` to configure PATH and check the version again.

#### 2. Install Python and its SDK (for Python calls)

```bash
brew install python
python3 --version
```

In your example project directory, create and activate a virtual environment:

```bash
python3 -m venv .venv
source .venv/bin/activate
python -m pip install openai
```

Save the Python example as `example.py` and run `python example.py` in the activated environment.

#### 3. Install Node.js and its SDK (for Node.js calls)

Install Node.js 24 LTS and add it to the current terminal's PATH:

```bash
brew install node@24
export PATH="$(brew --prefix node@24)/bin:$PATH"
node --version
npm --version
```

In your example project directory, install the SDK; skip initialization if `package.json` already exists:

```bash
npm init -y
npm install openai
```

Save the Node.js example as `example.mjs` and run `node example.mjs`. To use this Node.js version in new terminals, follow `brew info node@24` to configure your shell startup file.

#### 4. Set environment variables for this terminal

```bash
export LYROUTER_API_KEY="YOUR_LYROUTER_API_KEY"
export LYROUTER_BASE_URL="https://api.lyrouter.com"
```

Replace `YOUR_LYROUTER_API_KEY` with your saved key. These examples use LYRouter's public gateway, `https://api.lyrouter.com`; for a self-hosted deployment, substitute your own gateway URL. These variables apply only to the current terminal and its child processes; set them again in a new terminal. Keep the root URL without a trailing `/v1`; do not use the console's `/ai_gateway/` address.

References: [Python virtual environments](https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/), [Python on Windows](https://learn.microsoft.com/windows/dev-environment/python), [Node.js downloads](https://nodejs.org/en/download), [Homebrew](https://brew.sh/).

## Send a request

Replace MODEL_ID with your workspace's actual system model identifier.

**Request examples**

cURL:
**Linux / macOS (Bash / Zsh)**

```bash
curl "$LYROUTER_BASE_URL/v1/chat/completions" \
  -H "Authorization: Bearer $LYROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"MODEL_ID","messages":[{"role":"user","content":"Reply OK"}]}'
```

**Windows (PowerShell)**

Pass JSON through standard input to avoid PowerShell quoting differences. Replace `MODEL_ID` with your system model identifier:

```powershell
$body = @'
{"model":"MODEL_ID","messages":[{"role":"user","content":"Reply OK"}]}
'@
$body | curl.exe "$env:LYROUTER_BASE_URL/v1/chat/completions" `
  -H "Authorization: Bearer $env:LYROUTER_API_KEY" `
  -H "Content-Type: application/json" `
  --data-binary "@-"
```

Python:
```python
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["LYROUTER_API_KEY"],
    base_url=os.environ["LYROUTER_BASE_URL"] + "/v1",
)
result = client.chat.completions.create(
    model="MODEL_ID",
    messages=[{"role": "user", "content": "Reply OK"}],
)
print(result.choices[0].message.content)
```

Node.js:
```javascript
import OpenAI from "openai";
const client = new OpenAI({
  apiKey: process.env.LYROUTER_API_KEY,
  baseURL: process.env.LYROUTER_BASE_URL + "/v1",
});
const result = await client.chat.completions.create({
  model: "MODEL_ID",
  messages: [{ role: "user", content: "Reply OK" }],
});
console.log(result.choices[0].message.content);
```

## Verify

Confirm the response, then inspect [request logs](https://platform.lyrouter.com/ai_gateway/docs/logs/en) for status, model, and Token usage. Continue with a [tool guide](https://platform.lyrouter.com/ai_gateway/docs/tools/en) or the [API reference](https://platform.lyrouter.com/ai_gateway/docs/chat-completions/en). Existing provider credentials can be connected through [BYOK](https://platform.lyrouter.com/ai_gateway/docs/byok-choice/en).
