API Reference
Create Text Chat Request
Content-Type:
application/json
Request Parameters
Authorization
- Type
string
- Location
header
- RequiredYes
- DescriptionUse the following format for authentication:
Bearer <your api key>
(visit iFlow official website to login and get API KEY).
LLM Models
Parameter Name | Type | Required | Default | Description |
---|---|---|---|---|
messages | object[] | Yes | - | List of messages that make up the current conversation. |
messages.content | string | Yes | What opportunities and challenges will the Chinese large model industry face in 2025? | Content of the message. |
messages.role | enum<string> | Yes | user | Role of the message author. Possible values: user , assistant , system |
model | enum<string> | Yes | deepseek-r1 | Corresponding model name. To better improve service quality, we may periodically make changes to the models provided by this service, including but not limited to model online/offline adjustments and model service capability adjustments. We will notify you through appropriate means such as announcements and message pushes when possible. Please refer to the Quick Start page for supported models. |
frequency_penalty | number | No | 0.5 | Adjusts the frequency penalty for generated tokens to control repetitiveness. |
max_tokens | integer | No | 512 | Maximum number of tokens to generate. Value range: 1 < x < 8192 |
n | integer | No | 1 | Number of generated results to return. |
response_format | object | No | - | Object specifying the model output format. |
response_format.type | string | No | - | Type of response format. |
stop | string[] | null | No | - |
stream | boolean | No | false | If set to true , tokens will be returned progressively as Server-Sent Events (SSE). |
temperature | number | No | 0.7 | Controls the randomness of responses. Lower values make output more deterministic; higher values make output more random. |
tools | object[] | No | - | List of tools the model may call. Currently, only functions are supported as tools. Use this parameter to provide a list of functions for which the model may generate JSON input. Supports up to 128 functions. |
tools.function | object | No | - | Function object. |
tools.function.name | string | No | - | Name of the function to call. Must consist of letters, numbers, underscores, or hyphens, with a maximum length of 64. |
tools.function.description | string | No | - | Description of the function, used by the model to determine when and how to call it. |
tools.function.parameters | object | No | - | Parameters accepted by the function, described as a JSON Schema object. If parameters are not specified, a function with an empty parameter list is defined. |
tools.function.strict | boolean | null | No | false |
tools.type | enum<string> | No | function | Type of tool. Currently only supports function . |
top_k | number | No | 50 | Limits token selection range to the top k candidates. |
top_p | number | No | 0.7 | Nucleus sampling parameter used to dynamically adjust the selection range of each predicted token based on cumulative probability. |
Request Examples
- CURL
- Python
- Javascript
- Java
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": "What opportunities and challenges will the Chinese large model industry face in 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
}
}
]
}'
import requests
url = "https://apis.iflow.cn/v1/chat/completions"
payload = {
"model": "deepseek-r1",
"messages": [
{
"role": "user",
"content": "What opportunities and challenges will the Chinese large model industry face in 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
}
}
]
}
headers = {
"Authorization": "Bearer <iFlow API KEY>",
"Content-Type": "application/json"
}
response = requests.request("POST", url, json=payload, headers=headers)
print(response.text)
const url = "https://apis.iflow.cn/v1/chat/completions";
const payload = {
"model": "deepseek-r1",
"messages": [
{
"role": "user",
"content": "What opportunities and challenges will the Chinese large model industry face in 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
}
}
]
};
const headers = {
"Authorization": "Bearer <iFlow API KEY>",
"Content-Type": "application/json"
};
fetch(url, {
method: "POST",
headers: headers,
body: JSON.stringify(payload)
})
.then(response => response.json())
.then(data => console.log(data));
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.*;
// Build message object
Map<String, Object> message = new HashMap<>();
message.put("role", "user");
message.put("content", "What opportunities and challenges will the Chinese large model industry face in 2025?");
// Build tool function object
Map<String, Object> function = new HashMap<>();
function.put("description", "<string>");
function.put("name", "<string>");
function.put("parameters", new HashMap<>());
function.put("strict", false);
Map<String, Object> tool = new HashMap<>();
tool.put("type", "function");
tool.put("function", function);
// Build response format object
Map<String, Object> responseFormat = new HashMap<>();
responseFormat.put("type", "text");
// Build request parameters
Map<String, Object> requestBody = new HashMap<>();
requestBody.put("model", "deepseek-r1");
requestBody.put("messages", Arrays.asList(message));
requestBody.put("stream", false);
requestBody.put("max_tokens", 512);
requestBody.put("stop", Arrays.asList("null"));
requestBody.put("temperature", 0.7);
requestBody.put("top_p", 0.7);
requestBody.put("top_k", 50);
requestBody.put("frequency_penalty", 0.5);
requestBody.put("n", 1);
requestBody.put("response_format", responseFormat);
requestBody.put("tools", Arrays.asList(tool));
// Convert to JSON string
ObjectMapper mapper = new ObjectMapper();
String jsonBody = mapper.writeValueAsString(requestBody);
// Send request
HttpResponse<String> response = Unirest.post("https://apis.iflow.cn/v1/chat/completions")
.header("Authorization", "Bearer <iFlow API KEY>")
.header("Content-Type", "application/json")
.body(jsonBody)
.asString();
Response Parameters
- Non-streaming Output
- Streaming Output
Parameter Name | Type | Required | Default | Description |
---|---|---|---|---|
choices | object[] | Yes | - | List of choices generated by the model. |
choices.finish_reason | enum<string> | No | - | Reason for generation completion. Possible values: - stop : Natural completion. - eos : Reached sentence end marker. - length : Reached maximum token length limit. - tool_calls : Called a tool (such as a function). |
choices.message | object | Yes | - | Message object returned by the model. |
created | integer | Yes | - | Timestamp when the response was generated. |
id | string | Yes | - | Unique identifier of the response. |
model | string | Yes | - | Name of the model used. |
object | enum<string> | Yes | - | Type of response. Possible values: - chat.completion : Indicates this is a chat completion response. |
tool_calls | object[] | No | - | Tool calls generated by the model, such as function calls. |
tool_calls.function | object | No | - | Function called by the model. |
tool_calls.function.arguments | string | No | - | Arguments for the function call, generated by the model in JSON format. Note: The JSON generated by the model may be invalid or may generate parameters not belonging to the function definition. Please validate these parameters in your code before calling the function. |
tool_calls.function.name | string | No | - | Name of the function to call. |
tool_calls.id | string | No | - | Unique identifier of the tool call. |
tool_calls.type | enum<string> | No | - | Type of tool. Currently only supports function . Possible values: - function : Indicates this is a function call. |
usage | object | Yes | - | Token usage statistics. |
usage.completion_tokens | integer | Yes | - | Number of tokens used in the completion part. |
usage.prompt_tokens | integer | Yes | - | Number of tokens used in the prompt part. |
usage.total_tokens | integer | Yes | - | Total number of tokens used. |
Parameter Name | Type | Required | Default | Description |
---|---|---|---|---|
id | string | Yes | - | Unique identifier of the chat completion. Each chunk has the same ID. |
choices | object[] | Yes | - | List of choices generated by the model. |
choices.finish_reason | enum<string> | No | - | Reason for generation completion. Possible values: stop (natural completion), eos (reached sentence end marker), length (reached maximum token length limit), tool_calls (called a tool, such as a function). |
choices.message | object | Yes | - | Message object returned by the model. |
created | integer | Yes | - | Timestamp when the response was generated (Unix timestamp in seconds). |
model | string | Yes | - | Name of the model used. |
object | enum<string> | Yes | - | Type of response. Possible values: chat.completion (indicating this is a chat completion response). |
tool_calls | object[] | No | - | Tool calls generated by the model, such as function calls. |
tool_calls.function | object | No | - | Function called by the model. |
tool_calls.function.arguments | string | No | - | Arguments for the function call, generated by the model in JSON format. Note: The JSON generated by the model may be invalid or may generate parameters not belonging to the function definition. Please validate these parameters in your code before calling the function. |
tool_calls.function.name | string | No | - | Name of the function to call. |
tool_calls.id | string | No | - | Unique identifier of the tool call. |
tool_calls.type | enum<string> | No | - | Type of tool. Currently only supports function (indicating this is a function call). |
usage | object | Yes | - | Token usage statistics. |
usage.completion_tokens | integer | Yes | - | Number of tokens used in the completion part. |
usage.prompt_tokens | integer | Yes | - | Number of tokens used in the prompt part. |
usage.total_tokens | integer | Yes | - | Total number of tokens used (prompt + completion). |
delta | object | No | - | Chat completion delta generated by the streaming model response. |
choices.logprobs | object or null | No | - | Log probability information for this choice. |
choices.logprobs.content | array or null | No | - | List of message content tokens with log probability information. |
choices.logprobs.refusal | array or null | No | - | List of refusal message tokens and their log probability information. |
choices.logprobs.refusal.token | string | No | - | Token. |
choices.logprobs.refusal.logprob | number | No | - | Log probability for this token if it's among the top 20 most likely tokens; otherwise uses value -9999.0 to indicate extreme unlikelihood. |
choices.logprobs.refusal.bytes | array or null | No | - | List of integers representing the UTF-8 byte representation of the token. Used for cases requiring combination of multiple token byte representations. |
choices.logprobs.refusal.top_logprobs | array | No | - | List of the most likely tokens and their log probabilities at the current token position. In rare cases, the returned count may be less than requested. |
finish_reason | string or null | No | - | Reason why the model stopped generating tokens. |
index | integer | No | - | Index of the choice in the choice list. |
service_tier | string or null | No | - | Service tier used to process the request. |
system_fingerprint | string | No | - | Fingerprint representing the backend configuration of the model runtime. Can be used with the seed request parameter to understand potential backend changes that might affect determinism. |
Response Information
- Non-streaming
- Streaming
{
"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"
}
{"id":"<string>","object":"chat.completion.chunk","created":1694268190,"model":"<string>", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{"role":"assistant","content":""},"logprobs":null,"finish_reason":null}]}
{"id":"<string>","object":"chat.completion.chunk","created":1694268190,"model":"<string>", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{"content":"Hello"},"logprobs":null,"finish_reason":null}]}
....
{"id":"<string>","object":"chat.completion.chunk","created":1694268190,"model":"<string>", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{},"logprobs":null,"finish_reason":"stop"}]}