接口地址:https://api.siliconflow.cn/v1/chat/completions |
---|
返回格式:json |
请求方式:post |
请求示例:https://api.siliconflow.cn/v1/chat/completions |
名称 | 类型 | 必填 | 说明 |
---|---|---|---|
- | - | - | 太多参数了见文档地址 |
名称 | 类型 | 说明 |
---|---|---|
- | - | - |
{
"id": "<string>",
"choices": [{
"message": {
"role": "assistant",
"content": "<string>",
"reasoning_content": "<string>"
},
"finish_reason": "stop"
}],
"tool_calls": [{
"id": "<string>",
"type": "function",
"function": {
"name": "<string>",
"arguments": "<string>"
}
}],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123
},
"created": 123,
"model": "<string>",
"object": "chat.completion"
}
错误码 | 说明 |
---|---|
401 | 错误token |
404 | 接口地址错误 |
429 | 速率限制,请求被拒绝 |
503 | 模型服务超载 |
import requests
url = "https://api.siliconflow.cn/v1/chat/completions"
payload = {
"model": "deepseek-ai/DeepSeek-V3",
"messages": [
{
"role": "user",
"content": "中国大模型行业2025年将会迎来哪些机遇和挑战?"
}
],
"stream": False,
"max_tokens": 512,
"stop": None,
"temperature": 0.7,
"top_p": 0.7,
"top_k": 50,
"frequency_penalty": 0.5,
"n": 1,
"response_format": {"type": "text"},
"tools": [
{
"type": "function",
"function": {
"description": "<string>",
"name": "<string>",
"parameters": {},
"strict": False
}
}
]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.request("POST", url, json=payload, headers=headers)
print(response.text)
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://api.siliconflow.cn/v1/chat/completions"
payload := strings.NewReader("{\n \"model\": \"deepseek-ai/DeepSeek-V3\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"免费API,为您收集免费的接口服务,做一个api的搬运工\"\n }\n ],\n \"stream\": false,\n \"max_tokens\": 512,\n \"stop\": null,\n \"temperature\": 0.7,\n \"top_p\": 0.7,\n \"top_k\": 50,\n \"frequency_penalty\": 0.5,\n \"n\": 1,\n \"response_format\": {\n \"type\": \"text\"\n },\n \"tools\": [\n {\n \"type\": \"function\",\n \"function\": {\n \"description\": \"<string>\",\n \"name\": \"<string>\",\n \"parameters\": {},\n \"strict\": false\n }\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}