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

# 程式碼範例

> 使用 Python、JavaScript 或 cURL 透過 Chat Completions 呼叫 NexusAPI。

以下範例使用 OpenAI Chat Completions。先在[介面與模型能力矩陣](/zh-TW/developer/capability-matrix)確認模型與協定，並從模型廣場複製目前 Key 可用的模型 ID。

## 基本設定

* Base URL：`https://nexusapi.link/v1`
* API Key：在 [NexusAPI 控制台](https://nexusapi.link)的令牌管理建立
* Model ID：從模型廣場或 `/v1/models` 複製準確值

## Python

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

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

response = client.chat.completions.create(
    model="YOUR_MODEL_ID",
    messages=[{"role": "user", "content": "請簡短自我介紹。"}],
)

print(response.choices[0].message.content)
```

## JavaScript

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

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

const response = await client.chat.completions.create({
  model: "YOUR_MODEL_ID",
  messages: [{ role: "user", content: "請簡短自我介紹。" }],
});

console.log(response.choices[0].message.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":"測試連線"}]}'
```

請不要把真實 Key 寫入程式碼或提交到儲存庫。圖片生成使用不同端點，請看[圖片模型說明](/zh-TW/guide/image-generation)；可選參數與完整 schema 請查閱 [Apifox API 文件](https://nexusapi.apifox.cn/)。
