# 模型 SDK

开箱即用的模型：LLM、视觉、语音转写、实时转写，以及调度模型 Jev。不用自己去各家申请 key、不用自己记账——**每次调用都记在调用方所属公司的账上**（开发者 Key 记它的公司；Nexus 应用的访客用量记应用所属公司）。

```js
import { model } from "/developer/sdk/v1/aidc.js";
```

## 目录

| 模型 | 类型 | 输入 | 适合 |
| --- | --- | --- | --- |
| `deepseek-flash` | LLM | 文本 | 翻译、摘要、抽取、分类——最快最省（默认关闭思考） |
| `gpt-5.4-mini` | LLM | 文本、图片 | 结构化输出、轻量看图 |
| `gpt-5.5` | LLM | 文本、图片 | 复杂分析、长文写作（不对公开应用开放） |
| `gpt-6-luna` | 视觉 | 文本、图片 | 看图判断：质检、识别、读表 |
| `gpt-transcribe` | 语音 | 音频 | 文件转写，自带标点与语种识别，按秒计量 |
| `gpt-4o-mini-transcribe` | 语音 | 音频 | 更省的文件转写 |
| `gpt-live-transcribe` | 实时语音 | 音频流 | 边说边出字（见 [语音 SDK](voice.md)） |
| `jev-latest` | 调度 | 文本 | 在给定选项里快速分类 / 路由，只选不写 |

实时目录（含上游是否可用）：`GET /api/v1/models`，或 `aidc models`。

## 对话

```js
const reply = await model.text({ model: "deepseek-flash", messages: [{ role: "user", content: "用一句话介绍 AIDC" }] });

for await (const delta of model.stream({ model: "gpt-5.4-mini", messages })) output.textContent += delta;

const data = await model.json({
  model: "gpt-5.4-mini",
  messages,
  schema: { name: "invoice", schema: { type: "object", properties: { total: { type: "number" } }, required: ["total"], additionalProperties: false } },
});
```

图片输入：`content: [{ type: "text", text: "…" }, await model.image(blob)]`。

## 转写

```js
const { text } = await model.transcribe(audioBlob, { model: "gpt-transcribe", language: "zh" });
```

## Jev

```js
const answers = await model.decide("客户问：发票什么时候开？", {
  route: { instructions: "这条消息应该交给谁处理？", criteria: { finance: "开票、付款、报销", sales: "报价、合同", support: "使用问题" } },
});
// → { route: { choice: "finance", confidence: 0.93, probabilities: {…} } }
```

## 用任何 OpenAI SDK

模型 API 是 OpenAI 兼容的——改 `base_url` 即可：

```python
from openai import OpenAI
client = OpenAI(base_url="https://www.ai-dc.ai/api/v1/models", api_key=os.environ["AIDC_API_KEY"])
client.chat.completions.create(model="gpt-6-luna", messages=[...])
client.audio.transcriptions.create(model="gpt-transcribe", file=open("a.webm", "rb"))
```

支持的字段：`model`、`messages`（文本 / `image_url`）、`stream`、`temperature`、`top_p`、`max_tokens` / `max_completion_tokens`、`reasoning_effort`、`response_format`（`json_object` / `json_schema`）。其余字段会被忽略、不转发。

## 计费与额度

- 每次调用在台账里记一行：公司、Key、模型、token / 秒数、估算成本（按平台价目表；价目表里没有的模型成本记为空，不瞎估）。
- 开发者 Key：每把每分钟 120 次。
- Nexus 应用：按清单 `limits`——每个访客 IP 每分钟 `requestsPerMinute` 次、全体访客每天 `dailyTokens` 个 token、`realtimeSessionsPerDay` 场实时转写；用完返回 `quota_exhausted`，UTC 0 点恢复。
- 公开应用（任何人可访问）只能用上表中「对公开应用开放」的模型。

## 命令行

```bash
aidc models
aidc model chat -m deepseek-flash "把这段话翻成日语：…"
aidc model chat -m gpt-6-luna "图里有几个人？" --image photo.jpg
aidc model decide --state "发票什么时候开" --question route=交给谁 --choice route:finance=财务 --choice route:sales=销售
```
