> ## Documentation Index
> Fetch the complete documentation index at: https://wiki.llm.sg/llms.txt
> Use this file to discover all available pages before exploring further.

# Get started with llm.sg

> Set your llm.sg API credentials, discover a model ID, and send your first text request using cURL, Python, or the OpenAI JavaScript client library.

Connect your application to llm.sg by preparing an API key, choosing a model ID, and sending a text request.

> [!NOTE]
>
> These examples use the OpenAI Chat Completions format. The model endpoint's authentication requirement is verified. Authenticated discovery, chat, SDK compatibility, and streaming still require validation before publication.

## 1. Configure your API key

Follow [account and API keys](https://wiki.llm.sg/en/docs/account-and-api-keys.md) and set `LLM_SG_API_KEY` in the terminal or application environment where you will run the examples.

## 2. Choose a model

Request the available models:

```bash theme={null}
curl --fail-with-body --silent --show-error \
  'https://api.llm.sg/v1/models' \
  -H "Authorization: Bearer ${LLM_SG_API_KEY}"
```

Select a model suitable for text chat. If the endpoint uses the compatible list format, copy an entry's `id` from the `data` array. Confirm the actual response format and preserve the complete model ID.

On macOS or Linux:

```bash theme={null}
export LLM_SG_MODEL='YOUR_MODEL_ID'
```

On Windows PowerShell:

```powershell theme={null}
$env:LLM_SG_MODEL = 'YOUR_MODEL_ID'
```

Replace `YOUR_MODEL_ID` with an ID provided by llm.sg. Model aliases from another service may not work here.

## 3. Send a request

Choose one of the following approaches. All examples read `LLM_SG_API_KEY`; the SDK examples also read `LLM_SG_MODEL`.

> [tab] cURL
>
> Run this command in Bash or Zsh. Replace `YOUR_MODEL_ID` in the JSON body with the model you selected.
>
> ```bash theme={null}
> curl --fail-with-body --silent --show-error \
>   'https://api.llm.sg/v1/chat/completions' \
>   -H "Authorization: Bearer ${LLM_SG_API_KEY}" \
>   -H 'Content-Type: application/json' \
>   --data-raw '{
>     "model": "YOUR_MODEL_ID",
>     "messages": [
>       {"role": "user", "content": "Introduce yourself in one sentence."}
>     ]
>   }'
> ```

> [tab] Python
>
> Install the client library:
>
> ```bash theme={null}
> python -m pip install openai
> ```
>
> Save the code as `quickstart.py` and run `python quickstart.py`.
>
> ```python theme={null}
> import os
> from openai import OpenAI
>
> client = OpenAI(
>     api_key=os.environ["LLM_SG_API_KEY"],
>     base_url="https://api.llm.sg/v1",
> )
>
> response = client.chat.completions.create(
>     model=os.environ["LLM_SG_MODEL"],
>     messages=[{"role": "user", "content": "Introduce yourself in one sentence."}],
> )
> print(response.choices[0].message.content)
> ```

> [tab] JavaScript
>
> Install the client library:
>
> ```bash theme={null}
> npm install openai
> ```
>
> Save the code as `quickstart.mjs` and run `node quickstart.mjs`.
>
> ```javascript theme={null}
> import OpenAI from "openai";
>
> const apiKey = process.env.LLM_SG_API_KEY;
> const model = process.env.LLM_SG_MODEL;
> if (!apiKey || !model) {
>   throw new Error("Set LLM_SG_API_KEY and LLM_SG_MODEL first");
> }
>
> const client = new OpenAI({
>   apiKey,
>   baseURL: "https://api.llm.sg/v1",
> });
>
> const response = await client.chat.completions.create({
>   model,
>   messages: [{ role: "user", content: "Introduce yourself in one sentence." }],
> });
> console.log(response.choices[0].message.content);
> ```

## Read the result

For a compatible text response, read the answer from `choices[0].message.content`. If the response includes `usage`, use it to inspect token consumption. Token counts are separate from the final billed amount.

If a request fails, record the HTTP status, error message, and request ID, then follow [troubleshooting](https://wiki.llm.sg/en/docs/troubleshooting.md).

## Configure a third-party application

For clients that support a custom OpenAI-compatible endpoint, start with these settings and validate the integration:

| Setting | Value |
| - | - |
| Service type | Custom OpenAI-compatible service |
| Base URL | `https://api.llm.sg/v1` |
| API key | Your llm.sg API key |
| Model | The complete model ID supplied by llm.sg |

If the client asks for a full chat endpoint, use `https://api.llm.sg/v1/chat/completions`. Some clients append `/v1` themselves. Check the resulting request URL if you encounter path errors.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.