ff
This commit is contained in:
5
content/guides/_meta.js
Normal file
5
content/guides/_meta.js
Normal file
@@ -0,0 +1,5 @@
|
||||
export default {
|
||||
console: "???",
|
||||
api_keys: "API Key",
|
||||
streaming: "????",
|
||||
};
|
||||
26
content/guides/api_keys.mdx
Normal file
26
content/guides/api_keys.mdx
Normal file
@@ -0,0 +1,26 @@
|
||||
---
|
||||
title: API Key 管理
|
||||
sidebarTitle: API Key
|
||||
description: 创建、轮换与权限最佳实践
|
||||
---
|
||||
|
||||
# API Key 管理
|
||||
|
||||
## 创建
|
||||
|
||||
控制台 → **设置 → API Key** → **创建**。建议命名包含环境与用途,例如 `prod-report-agent`。
|
||||
|
||||
## 存储
|
||||
|
||||
- 使用环境变量:`HAIYUSHUKE_API_KEY`
|
||||
- 密钥管理系统(KMS / Vault)中保存,勿提交至 Git
|
||||
|
||||
## 轮换流程
|
||||
|
||||
1. 创建新 Key
|
||||
2. 在应用配置中灰度切换
|
||||
3. 确认流量稳定后禁用旧 Key
|
||||
|
||||
## 泄露应急
|
||||
|
||||
若 Key 已泄露:立即 **禁用** 该 Key → 新建 → 排查仓库与 CI 日志是否残留。
|
||||
30
content/guides/console.mdx
Normal file
30
content/guides/console.mdx
Normal file
@@ -0,0 +1,30 @@
|
||||
---
|
||||
title: 控制台使用
|
||||
sidebarTitle: 控制台
|
||||
description: 控制台主要功能与导航说明
|
||||
---
|
||||
|
||||
# 控制台使用指南
|
||||
|
||||
控制台地址:[https://console.haiyushuke.com](https://console.haiyushuke.com)
|
||||
|
||||
## 主要模块
|
||||
|
||||
1. **概览**:用量、余额与近期调用趋势
|
||||
2. **模型广场**:浏览可用模型、定价与能力说明
|
||||
3. **API Key**:创建、轮换、禁用密钥
|
||||
4. **调用日志**(若已开通):按时间筛选请求与错误
|
||||
5. **账单**:充值、发票与明细导出
|
||||
|
||||
## 推荐工作流
|
||||
|
||||
1. 创建 API Key
|
||||
2. 在模型广场选择目标模型
|
||||
3. 使用 SDK 或 cURL 完成联调
|
||||
4. 在概览与调用日志中核对用量
|
||||
|
||||
## 权限与安全
|
||||
|
||||
- 为不同环境(开发 / 预发 / 生产)使用不同 Key
|
||||
- 定期轮换 Key;泄露后立即 **禁用** 并新建
|
||||
- 生产环境勿将 Key 写入前端 bundle
|
||||
38
content/guides/streaming.mdx
Normal file
38
content/guides/streaming.mdx
Normal file
@@ -0,0 +1,38 @@
|
||||
---
|
||||
title: 流式调用
|
||||
sidebarTitle: 流式调用
|
||||
description: SSE 流式输出接入说明
|
||||
---
|
||||
|
||||
# 流式调用
|
||||
|
||||
在请求体中设置 `"stream": true`,服务端以 SSE 形式返回增量内容。
|
||||
|
||||
## cURL
|
||||
|
||||
```bash
|
||||
curl https://api.haiyushuke.com/v1/chat/completions \
|
||||
-H "Authorization: Bearer YOUR_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"model":"gpt-4o-mini","stream":true,"messages":[{"role":"user","content":"写一首四句诗"}]}'
|
||||
```
|
||||
|
||||
## OpenAI SDK(Node)
|
||||
|
||||
```ts
|
||||
const stream = await client.chat.completions.create({
|
||||
model: "gpt-4o-mini",
|
||||
stream: true,
|
||||
messages: [{ role: "user", content: "你好" }],
|
||||
});
|
||||
|
||||
for await (const chunk of stream) {
|
||||
const text = chunk.choices[0]?.delta?.content;
|
||||
if (text) process.stdout.write(text);
|
||||
}
|
||||
```
|
||||
|
||||
## 注意
|
||||
|
||||
- 客户端需正确处理连接中断与超时重试
|
||||
- 流式场景下计费通常按 **输出 token** 累计,以账单规则为准
|
||||
Reference in New Issue
Block a user