跳至主要内容

API 手冊

建立文字對話請求

Content-Type:application/json

請求參數說明

Authorization
  • 類型
    string
  • 位置
    header
  • 是否必填
  • 描述
    使用以下格式進行身份驗證:Bearer <your api key>(訪問 iFlow 官網登入獲取 API KEY)。

LLM 模型

參數名類型是否必填預設值描述
messagesobject[]-構成當前對話的訊息列表。
messages.contentstring2025年中國大模型行業將會迎來哪些機遇和挑戰?訊息的內容。
messages.roleenum<string>user訊息作者的角色。 可選值:user
, assistant
, system
modelenum<string>deepseek-r1對應的模型名稱。 為更好的提升服務品質,我們將不定期對本服務提供的模型做相關變更,包括但不限於模型上下線、模型服務能力調整,我們會在可行的情況下以公告、訊息推送等適當的方式進行通知。 支援的模型請參考快速開始頁面。
frequency_penaltynumber0.5調整生成 token 的頻率懲罰,用於控制重複性。
max_tokensinteger512生成的最大 token 數量。 取值範圍:1 < x < 8192
ninteger1返回的生成結果數量。
response_formatobject-指定模型輸出格式的物件。
response_format.typestring-回應格式的類型。
stopstring[]null-
streambooleanfalse如果設定為 true
,token 將作為伺服器發送事件(SSE)逐步返回。
temperaturenumber0.7控制回應的隨機性。值越低,輸出越確定;值越高,輸出越隨機。
toolsobject[]-模型可能呼叫的工具列表。目前僅支援函數作為工具。使用此參數提供一個函數列表,模型可能會為其生成 JSON 輸入。最多支援 128 個函數。
tools.functionobject-函數物件。
tools.function.namestring-要呼叫的函數名稱。必須由字母、數字、底線或連字號組成,最大長度為 64。
tools.function.descriptionstring-函數的描述,用於模型選擇何時以及如何呼叫該函數。
tools.function.parametersobject-函數接受的參數,描述為 JSON Schema 物件。如果不指定參數,則定義了一個空參數列表的函數。
tools.function.strictbooleannullfalse
tools.typeenum<string>function工具的類型。目前僅支援 function
top_knumber50限制 token 選擇範圍為前 k 個候選。
top_pnumber0.7核取樣參數,用於根據累積機率動態調整每個預測 token 的選擇範圍。

請求舉例

curl --request POST \
--url https://apis.iflow.cn/v1/chat/completions \
--header 'Authorization: Bearer <iflow API KEY>' \
--header 'Content-Type: application/json' \
--data '{
"model": "deepseek-r1",
"messages": [
{
"role": "user",
"content": "2025年中國大模型行業將會迎來哪些機遇和挑戰?"
}
],
"stream": false,
"max_tokens": 512,
"stop": [
"null"
],
"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
}
}
]
}'

回應參數

參數名類型是否必填預設值描述
choicesobject[]-模型生成的選擇列表。
choices.finish_reasonenum<string>-生成結束的原因。 可選值: - stop
: 自然結束。 - eos
: 到達句子結束符。 - length
: 達到最大 token 長度限制。 - tool_calls
: 呼叫了工具(如函數)。
choices.messageobject-模型返回的訊息物件。
createdinteger-回應生成的時間戳。
idstring-回應的唯一標識符。
modelstring-使用的模型名稱。
objectenum<string>-回應類型。 可選值: - chat.completion
: 表示這是一個聊天完成回應。
tool_callsobject[]-模型生成的工具呼叫,例如函數呼叫。
tool_calls.functionobject-模型呼叫的函數。
tool_calls.function.argumentsstring-函數呼叫的參數,由模型以 JSON 格式生成。 注意:模型生成的 JSON 可能無效,或者可能會生成不屬於函數定義的參數。在呼叫函數前,請在程式碼中驗證這些參數。
tool_calls.function.namestring-要呼叫的函數名稱。
tool_calls.idstring-工具呼叫的唯一標識符。
tool_calls.typeenum<string>-工具的類型。 目前僅支援 function
。 可選值: - function
: 表示這是一個函數呼叫。
usageobject-Token 使用情況統計。
usage.completion_tokensinteger-完成部分使用的 token 數量。
usage.prompt_tokensinteger-提示部分使用的 token 數量。
usage.total_tokensinteger-總共使用的 token 數量。

回應資訊

        {
"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"
}