File size: 1,607 Bytes
ffde0c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# 中转站使用说明

这是一个兼容 OpenAI 格式的中文 AI API 中转站。你拿到管理员发给你的 API Key 后,就可以在支持 OpenAI 接口的软件里使用。

## 基本信息

Base URL:

```text
https://<owner>-<space>.hf.space/v1
```

示例:如果管理员的 Hugging Face 用户名是 `liuyiyang1439`,Space 名叫 `zhongzhuanzhan`,那 Base URL 就是:

```text
https://liuyiyang1439-zhongzhuanzhan.hf.space/v1
```

API Key:

```text
由管理员单独发放,请不要公开分享
```

## 常见软件填写方式

在支持 OpenAI 兼容接口的软件里填写:

- API Base / Base URL:`https://<owner>-<space>.hf.space/v1`
- API Key:你的用户 API Key
- Model:管理员告诉你的可用模型名

## curl 测试`<user-api-key>``<model>` 换成你的实际内容:

```powershell
$headers = @{
  "Authorization" = "Bearer <user-api-key>"
  "Content-Type" = "application/json"
}

$body = @{
  model = "<model>"
  messages = @(
    @{ role = "user"; content = "你好,请用中文简单介绍你自己。" }
  )
} | ConvertTo-Json -Depth 5

Invoke-RestMethod `
  -Uri "https://<owner>-<space>.hf.space/v1/chat/completions" `
  -Method POST `
  -Headers $headers `
  -Body $body
```

## 注意事项

- 不要把 API Key 发到群里、论坛或公开仓库。
- 如果提示 `401`,通常是 API Key 写错、被禁用,或 Base URL 少了 `/v1`- 如果提示 `503`,通常是当前模型没有可用上游账号、模型名不在可用列表,或上游暂时不可用。
- 额度、倍率、可用模型以管理员设置为准。