|
1 | | -``` |
2 | | -curl 'https://puter.com/puterai/chat/models' \ |
3 | | - -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7' \ |
4 | | - -H 'Accept-Language: zh-CN,zh;q=0.9' \ |
5 | | - -H 'Cache-Control: no-cache' \ |
6 | | - -H 'Connection: keep-alive' \ |
7 | | - -b '_clck=trp08g%5E2%5Eg1c%5E0%5E2156; __stripe_mid=1ae8b1e7-34aa-4d9c-a0bc-e00348bd4e36e7b24e; __stripe_sid=937ef572-58cc-46d3-bc2e-dbac15385aa77e545a; puter_auth_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0IjoicyIsInYiOiIwLjAuMCIsInUiOiJaMmZNZ2FzOFJSeXhSS3M3S1FuWnpnPT0iLCJ1dSI6Im02UmZFbkEzU0VpUjk0TVZadnJYZkE9PSIsImlhdCI6MTc2NDE3MTc0OH0.2pC0C8jAvpFiUpOcVza1V7uCnnfVza9kBLX2p5PcFyw; _clsk=1ydouus%5E1764171905602%5E6%5E1%5Ei.clarity.ms%2Fcollect' \ |
8 | | - -H 'Pragma: no-cache' \ |
9 | | - -H 'Sec-Fetch-Dest: document' \ |
10 | | - -H 'Sec-Fetch-Mode: navigate' \ |
11 | | - -H 'Sec-Fetch-Site: none' \ |
12 | | - -H 'Sec-Fetch-User: ?1' \ |
13 | | - -H 'Upgrade-Insecure-Requests: 1' \ |
14 | | - -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36' \ |
15 | | - -H 'sec-ch-ua: "Chromium";v="142", "Google Chrome";v="142", "Not_A Brand";v="99"' \ |
16 | | - -H 'sec-ch-ua-mobile: ?0' \ |
17 | | - -H 'sec-ch-ua-platform: "macOS"' |
18 | | -``` |
19 | | - |
20 | | -## 对 Puter.com 的请求 |
21 | | - |
22 | | -### 1. 获取模型列表 |
23 | | -- **URL**: `https://puter.com/puterai/chat/models` |
24 | | -- **方法**: GET |
25 | | -- **响应**: |
26 | | -```json |
27 | | -{ |
28 | | - "models": ["model-id-1", "model-id-2", ...] |
29 | | -} |
30 | | -``` |
31 | | - |
32 | | -### 2. 调用 AI 驱动 |
33 | | -- **URL**: `https://api.puter.com/drivers/call` |
34 | | -- **方法**: POST |
35 | | -- **请求头**: |
36 | | - - `Host`: api.puter.com |
37 | | - - `Authorization`: Bearer {JWT_TOKEN} |
38 | | - - `Content-Type`: application/json;charset=UTF-8 |
39 | | - - `Origin`: https://docs.puter.com |
40 | | - - `Referer`: https://docs.puter.com/ |
41 | | - |
42 | | -- **请求体**: |
43 | | -```json |
44 | | -{ |
45 | | - "interface": "puter-chat-completion", |
46 | | - "driver": "openai-completion|deepseek|xai|claude|mistral", |
47 | | - "test_mode": false, |
48 | | - "method": "complete", |
49 | | - "args": { |
50 | | - "messages": [...], |
51 | | - "model": "model-name", |
52 | | - "stream": true|false |
53 | | - } |
54 | | -} |
55 | | -``` |
56 | | - |
57 | | -- **响应** (非流式): |
58 | | -```json |
59 | | -{ |
60 | | - "result": { |
61 | | - "message": { |
62 | | - "content": "text" | [{"type": "text", "text": "..."}] |
63 | | - }, |
64 | | - "usage": { |
65 | | - "input_tokens": 0, |
66 | | - "output_tokens": 0 |
67 | | - } |
68 | | - } |
69 | | -} |
70 | | -``` |
71 | | - |
72 | | -- **响应** (流式): 每行一个 JSON 对象 |
73 | | -```json |
74 | | -{"text": "content"} |
75 | | -``` |
76 | | -或 |
77 | | -```json |
78 | | -{"result": {"message": {"content": "text" | [...]}}} |
79 | | -``` |
80 | | - |
81 | | -## API 端点 |
82 | | - |
83 | | -### GET /v1/models |
84 | | -获取可用模型列表 |
85 | | - |
86 | | -**响应格式**: |
87 | | -```json |
88 | | -{ |
89 | | - "object": "list", |
90 | | - "data": [ |
91 | | - { |
92 | | - "id": "model-id", |
93 | | - "object": "model", |
94 | | - "created": 1234567890, |
95 | | - "owned_by": "openai|deepseek|xai|anthropic|mistral|unknown" |
96 | | - } |
97 | | - ] |
98 | | -} |
99 | | -``` |
100 | | - |
101 | | -### POST /v1/chat/completions |
102 | | -创建聊天补全 |
103 | | - |
104 | | -**请求头**: |
105 | | -- `Authorization`: Bearer {AUTH_TOKEN} |
106 | | - |
107 | | -**请求体**: |
108 | | -```json |
109 | | -{ |
110 | | - "model": "model-name", |
111 | | - "messages": [ |
112 | | - {"role": "user", "content": "Hello"} |
113 | | - ], |
114 | | - "stream": false |
115 | | -} |
116 | | -``` |
117 | | - |
118 | | -**响应格式** (非流式): |
119 | | -```json |
120 | | -{ |
121 | | - "id": "chatcmpl-1234567890", |
122 | | - "object": "chat.completion", |
123 | | - "created": 1234567890, |
124 | | - "model": "model-name", |
125 | | - "choices": [ |
126 | | - { |
127 | | - "index": 0, |
128 | | - "message": { |
129 | | - "role": "assistant", |
130 | | - "content": "响应内容" |
131 | | - }, |
132 | | - "finish_reason": "stop" |
133 | | - } |
134 | | - ], |
135 | | - "usage": { |
136 | | - "prompt_tokens": 10, |
137 | | - "completion_tokens": 20, |
138 | | - "total_tokens": 30 |
139 | | - } |
140 | | -} |
141 | | -``` |
142 | | - |
143 | | -**响应格式** (流式 - SSE): |
144 | | -``` |
145 | | -data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","created":xxx,"model":"xxx","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]} |
146 | | -
|
147 | | -data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","created":xxx,"model":"xxx","choices":[{"index":0,"delta":{"content":"内容"},"finish_reason":null}]} |
148 | | -
|
149 | | -data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","created":xxx,"model":"xxx","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]} |
150 | | -
|
151 | | -data: [DONE] |
152 | | -``` |
153 | | - |
154 | | -## 环境变量 |
155 | | - |
156 | | -- `JWT_TOKEN`: Puter API 的 JWT 令牌(多个用逗号分隔) |
157 | | -- `AUTH_TOKEN`: 本服务的认证令牌(多个用逗号分隔) |
158 | | -- `PORT`: 服务端口(默认 8001) |
159 | | - |
160 | | -## 驱动映射 |
161 | | - |
162 | | -- `deepseek` → deepseek |
163 | | -- `grok` → xai |
164 | | -- `claude` → claude |
165 | | -- `mistral/codestral` → mistral |
166 | | -- 其他 → openai-completion |
| 1 | +# 教程 |
| 2 | +https://docs.puter.com/playground/ai-chatgpt/ |
167 | 3 |
|
| 4 | + |
0 commit comments