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

# Code examples

> Use NexusAPI with Python, JavaScript, or cURL through Chat Completions.

The examples below use OpenAI Chat Completions. First confirm the selected model and protocol in the [API and model capability matrix](/en/developer/capability-matrix). For optional fields and full schemas, use the [Apifox API reference](https://nexusapi.apifox.cn/).

## Core settings

* **Base URL:** `https://nexusapi.link/v1`
* **API key:** create it in the [NexusAPI console](https://nexusapi.link)
* **Model ID:** copy the exact ID from the Model Marketplace for the current key's group

## Python

```python theme={"system"}
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://nexusapi.link/v1",
)

stream = client.chat.completions.create(
    model="YOUR_MODEL_ID",
    messages=[{"role": "user", "content": "Introduce yourself."}],
    stream=True,
)

for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="", flush=True)
```

## JavaScript

```js theme={"system"}
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.NEXUSAPI_API_KEY,
  baseURL: "https://nexusapi.link/v1",
});

const stream = await client.chat.completions.create({
  model: "YOUR_MODEL_ID",
  messages: [{ role: "user", content: "Introduce yourself." }],
  stream: true,
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content || "");
}
```

## cURL

```bash theme={"system"}
curl 'https://nexusapi.link/v1/chat/completions' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -d '{
    "model": "YOUR_MODEL_ID",
    "messages": [{"role": "user", "content": "Test that the API is reachable"}]
  }'
```

Do not put an actual key in source code or commit it to a repository. Image generation uses a different endpoint; see the [image model guide](/en/guide/image-generation).
