---
title: 快速开始
---

New API 提供兼容 OpenAI 的模型调用接口。准备好服务地址和 API Key 后，即可使用现有 OpenAI SDK 或标准 HTTP 客户端接入。

## 1. 配置环境变量

```bash
export NEW_API_BASE_URL="https://api.example.com/v1"
export NEW_API_KEY="sk-your-api-key"
```

PowerShell：

```powershell
$env:NEW_API_BASE_URL = "https://api.example.com/v1"
$env:NEW_API_KEY = "sk-your-api-key"
```

## 2. 获取模型列表

```bash
curl "$NEW_API_BASE_URL/models" \
  -H "Authorization: Bearer $NEW_API_KEY"
```

## 3. 发起对话请求

```bash
curl "$NEW_API_BASE_URL/chat/completions" \
  -H "Authorization: Bearer $NEW_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "YOUR_MODEL_ID",
    "messages": [
      {"role": "user", "content": "你好，请用一句话介绍你自己"}
    ]
  }'
```

成功响应：

```json
{
  "id": "chatcmpl-example",
  "object": "chat.completion",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "你好，我是通过统一 API 接入的 AI 助手。"
      },
      "finish_reason": "stop"
    }
  ]
}
```

## SDK 接入

### Python

```python
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["NEW_API_KEY"],
    base_url=os.environ["NEW_API_BASE_URL"],
)

response = client.chat.completions.create(
    model="YOUR_MODEL_ID",
    messages=[{"role": "user", "content": "你好"}],
)
print(response.choices[0].message.content)
```

### Node.js

```typescript
import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: process.env.NEW_API_KEY,
  baseURL: process.env.NEW_API_BASE_URL,
});

const response = await client.chat.completions.create({
  model: 'YOUR_MODEL_ID',
  messages: [{ role: 'user', content: '你好' }],
});

console.log(response.choices[0].message.content);
```

完整字段定义与更多接口请查看 [模型 API Reference](/reference/relay)。
