# NextModel agent setup

这里是 NextModel 官方的 Agent 接入说明。编程 Agent 可以按照它自行完成接入配置。

Every guide below targets the same OpenAI-compatible endpoint.

- API base URL: https://api.nextmodel.app/v1
- Authentication header: `Authorization: Bearer <YOUR_API_KEY>`
- Example model ID: claude-sonnet-4-5

## Instructions for the agent

Fetch and execute the appropriate instructions below to configure the tool yourself. Complete every step directly and do not ask the user to run commands for you.

1. Ask the user for their NextModel API key (never ask them to paste it anywhere except this Agent's secure config).
2. Set the tool's provider base URL to https://api.nextmodel.app/v1 — the value shown above, never a hardcoded host.
3. Follow the matching `## <Agent name>` section below end to end, write the configuration yourself, then run that section's verification step before reporting back.

Work through the section that matches the tool in front of you, top to bottom.

## Codex CLI

OpenAI 的终端编程代理，指向 NextModel。

### 1. 获取你的 NextModel API 密钥

在 NextModel 控制台创建密钥并复制，下一步会把它接入你的 shell。

### 2. 在 ~/.codex/config.toml 中添加自定义模型提供商

wire_api = "chat" 让 Codex 走 NextModel 提供的 OpenAI 兼容 chat completions 端点。

```TOML
model = "claude-sonnet-4-5"
model_provider = "nextmodel"

[model_providers.nextmodel]
name = "NextModel"
base_url = "https://api.nextmodel.app/v1"
env_key = "NEXTMODEL_API_KEY"
wire_api = "chat"
```

Docs: https://github.com/openai/codex

### 3. 把密钥导出为环境变量

Codex 按 env_key 指定的变量名读取密钥。把它写进 shell 配置即可，不要写进会提交的文件。

```Shell
export NEXTMODEL_API_KEY=<YOUR_API_KEY>
```

### 4. 试跑第一条指令

能正常流式返回，就说明 provider 已经生效。

```Shell
codex "Explain what this repository does and list its entry points"
```


## Cursor

AI 优先的 IDE，接上你自己的端点。

### 1. 获取你的 NextModel API 密钥

在 NextModel 控制台创建密钥，保留这个页面——下一步要粘贴进 Cursor。

### 2. 在 Settings 中把 Cursor 指向 NextModel

Cursor Settings → Models：把你的 NextModel 密钥粘贴到 OpenAI 字段并点击 Save。要让 OpenAI 格式的请求发往 NextModel，在同一面板打开 Override OpenAI Base URL 开关，填入 https://api.nextmodel.app/v1，再把 claude-sonnet-4-5 登记为自定义模型。不同 Cursor 版本中控件名称可能略有差异。

Docs: https://cursor.com/help/models-and-usage/api-keys

### 3. 用一次请求确认端点可用

返回 JSON 就说明地址、密钥和模型都对得上——Cursor 里填的正是同一组值。

```Shell
curl "https://api.nextmodel.app/v1/chat/completions" \
  -H "Authorization: Bearer <YOUR_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{"model": "claude-sonnet-4-5", "messages": [{"role": "user", "content": "ping"}]}'
```

### 4. 在 Composer 中选择 claude-sonnet-4-5

打开 Composer 或聊天面板的模型选择器，选中刚添加的模型。


## Cline

VS Code 里的自主编程代理，用你自己的密钥。

### 1. 获取你的 NextModel API 密钥

在 NextModel 控制台创建密钥——Cline 的每个请求都会带上它。

### 2. 在 VS Code 中安装 Cline 扩展

也可以在扩展面板里搜索 Cline 直接安装。

```Shell
code --install-extension saoudrizwan.claude-dev
```

Docs: https://marketplace.visualstudio.com/items?itemName=saoudrizwan.claude-dev

### 3. 选择 OpenAI Compatible 并填写 provider 字段

在 Cline 设置中把 API Provider 设为 OpenAI Compatible（不是 OpenAI），Base URL 填 https://api.nextmodel.app/v1，API Key 填你的 NextModel 密钥，Model ID 填 claude-sonnet-4-5。

Docs: https://docs.cline.bot

### 4. 交给 Cline 第一个任务

在 Cline 面板里发起任务——请求会计入你的 NextModel 密钥。


## Cherry Studio

开箱即说 OpenAI 的桌面聊天客户端。

### 1. 获取你的 NextModel API 密钥

在 NextModel 控制台创建密钥——桌面应用会把它保存在本地。

### 2. 在设置 → 模型服务中添加提供商

打开设置 → 模型服务，添加提供商，API 地址填 https://api.nextmodel.app/v1，密钥粘贴到 API 密钥。

Docs: https://docs.cherryai.com.cn

### 3. 在该提供商下添加 claude-sonnet-4-5

使用提供商的添加模型功能，模型 ID 填 claude-sonnet-4-5，之后它会出现在对话的模型选择器里。

### 4. 用一次请求验证

在任意终端运行——返回 JSON 就说明地址、密钥和模型都对得上。

```Shell
curl "https://api.nextmodel.app/v1/chat/completions" \
  -H "Authorization: Bearer <YOUR_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{"model": "claude-sonnet-4-5", "messages": [{"role": "user", "content": "ping"}]}'
```


## OpenAI SDK

任意 OpenAI SDK，只差一个 base_url。

### 1. 获取你的 NextModel API 密钥

在 NextModel 控制台创建密钥，并导出为 NEXTMODEL_API_KEY，方便下面的片段读取。

```Shell
export NEXTMODEL_API_KEY=<YOUR_API_KEY>
```

### 2. 把 Python 客户端指向 NextModel

与默认 OpenAI 配置相比，唯一的变化就是 base_url。

```Python
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.nextmodel.app/v1",
    api_key=os.environ["NEXTMODEL_API_KEY"],
)

resp = client.chat.completions.create(
    model="claude-sonnet-4-5",
    messages=[{"role": "user", "content": "Say hello in one sentence."}],
)
print(resp.choices[0].message.content)
```

Docs: https://github.com/openai/openai-python

### 3. 或者使用 Node 客户端

TypeScript 同理：baseURL 是唯一新增的参数。

```TypeScript
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.nextmodel.app/v1",
  apiKey: process.env.NEXTMODEL_API_KEY,
});

const resp = await client.chat.completions.create({
  model: "claude-sonnet-4-5",
  messages: [{ role: "user", content: "Say hello in one sentence." }],
});
console.log(resp.choices[0].message.content);
```

Docs: https://github.com/openai/openai-node

### 4. 不要把密钥写进代码

两个客户端都从环境变量读取密钥——本地用 dotenv 加载，生产环境用平台的密钥管理服务。
