Image-Text Chat Completion
Description
Create model responses based on given chat dialogue information, supporting image or video-related information in the conversation history. Images and videos cannot be provided simultaneously:
- If images are provided, up to 6 images can be accepted. Exceeding this limit will result in an error response.
- If a video is provided, only 1 video can be accepted. Exceeding this limit will result in an error response.
- Providing both images and videos will result in an error response.
Request URL
[POST] https://api.sensenova.cn/v1/llm/chat-completions
Request Header
No special headers required. Refer to API Authentication
Request Body
Note: For each request, the total number of tokens input by the user (i.e., the total number of tokens in all
content) + the maximum number of tokens the user expects the model to generate (i.e., the value ofmax_new_tokens) must be <= the model's maximum context length (for different models' context length support, refer to Model List).
| Name | Type | Required | Default | Optional Values | Description |
|---|---|---|---|---|---|
| model | string | Yes | - | Refer to Model List | Model ID |
| messages | object[] | Yes | - | - | Dialogue context input to the model, each object in the array represents a piece of chat context |
| max_new_tokens | int | No | 1024 | [1,16384] | Maximum number of tokens expected to be generated by the model (different models support different context lengths, so the maximum value varies, refer to Model List) |
| repetition_penalty | float | No | 1.0 | (0,2] | Repetition penalty coefficient, 1 means no penalty, greater than 1 tends to generate non-repetitive tokens, less than 1 tends to generate repetitive tokens, recommended range is [1,1.2] |
| stream | boolean | No | false | Enable: true Disable: false | Whether to use streaming transmission. If enabled, data will be returned as data-only SSE (server-sent events) with intermediate results and end with data: [DONE] |
| temperature | float | No | 0.8 | (0,2] | Temperature sampling parameter, values greater than 1 tend to generate more diverse responses, values less than 1 tend to generate more stable responses (supports up to six decimal places) |
| top_p | float | No | 0.7 | (0,1) | Nucleus sampling parameter, when decoding and generating tokens, sampling is done from the smallest token set whose cumulative probability is greater than or equal to top_p |
| user | string | No | - | - | External user ID, application developers can pass in the application system user ID for tracking |
messagessection parameters:
| Name | Type | Required | Default | Optional Values | Description |
|---|---|---|---|---|---|
| role | string | Yes | - | Enum values user assistant system | Role of the message author, enum values. Note that the last item in the array must be user |
| content | object[] | Yes | - | - | Content of the message |
contenttext section, can be plural, parameters are as follows:
| Name | Type | Required | Default | Optional Values | Description |
|---|---|---|---|---|---|
| type | string | Yes | text | - | Message content type |
| text | string | Yes | - | - | Text content |
contentimage part, can be plural, choose one of the following formats, different image information can choose different parameter formats, parameters are as follows:
| Name | Type | Required | Default | Optional Values | Description |
|---|---|---|---|---|---|
| type | string | Yes | image_url | - | Message content type |
| image_url | string | Yes | - | - | Image URL |
| Name | Type | Required | Default | Optional Values | Description |
|---|---|---|---|---|---|
| type | string | Yes | image_file_id | - | Message content type |
| image_file_id | string | Yes | - | - | File ID of the image uploaded via the file management interface |
| Name | Type | Required | Default | Optional Values | Description |
|---|---|---|---|---|---|
| type | string | Yes | image_base64 | - | Message content type |
| image_base64 | string | Yes | - | - | Base64 encoded content of the image |
contentvideo part, can only be singular, choose one of the following formats, cannot coexist with image part, parameters are as follows:
| Name | Type | Required | Default | Options | Description |
|---|---|---|---|---|---|
| type | string | Yes | video_url | - | Message content type |
| video_url | string | Yes | - | - | Video file URL |
| Name | Type | Required | Default | Options | Description |
|---|---|---|---|---|---|
| type | string | Yes | video_file_id | - | Message content type |
| video_file_id | string | Yes | - | - | File ID of the video uploaded via file management interface |
Request Example
curl --request POST "https://api.sensenova.cn/v1/llm/chat-completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $API_TOKEN" \
-d '{
"model": "string",
"messages": [
{
"role": "string",
"content": [
{
"type": "image_url",
"image_url": "string"
},
{
"type": "text",
"text": "string"
}
]
}
],
"max_new_tokens": 1024,
"repetition_penalty": 1.0,
"stream": false,
"temperature": 0.8,
"top_p": 0.7,
"user": "string"
}'
Response
| Name | Type | Description |
|---|---|---|
| data | object | Generated content |
datasection parameters:
| Name | Type | Description |
|---|---|---|
| id | string | Message ID |
| choices | object[] | List of generated responses |
| usage | object | Token usage |
choicessection parameters:
| Name | Type | Description |
|---|---|---|
| message | string | Generated response content for non-streaming requests |
| finish_reason | string | Reason for stopping generation, enum values Stopped by end token: stop Stopped by reaching maximum generation length: length Stopped by triggering sensitive words: sensitive Stopped by reaching model context length limit: context |
| index | int | Index of the generated response |
| role | string | Role of the response message |
| delta | string | Generated response content for streaming requests |
usagesection parameters:
| Name | Type | Description |
|---|---|---|
| prompt_tokens | int | Number of tokens in user input |
| knowledge_tokens | int | Number of tokens for knowledge base content input to the model (non-zero only if knowledge base is used and content is retrieved) |
| completion_tokens | int | Number of tokens for generated message |
| total_tokens | int | Total number of tokens |
Response Example
- Streaming
data:{"data":{"id":"123456789012345","choices":[{"delta":"This","finish_reason":"","index": 0,"role":"assistant"}],"usage":{"prompt_tokens":6,"knowledge_tokens": 0,"completion_tokens":1,"total_tokens":7}},"status":{"code":0, "message": "ok"}}
data:{"data":{"id":"123456789012345","choices":[{"delta":"is","finish_reason":"","index": 0,"role":"assistant"}],"usage":{"prompt_tokens":6,"knowledge_tokens": 0,"completion_tokens":2,"total_tokens":8}},"status":{"code":0, "message": "ok"}}
data:{"data":{"id":"123456789012345","choices":[{"delta":"a","finish_reason":"","index": 0,"role":"assistant"}],"usage":{"prompt_tokens":6,"knowledge_tokens": 0,"completion_tokens":3,"total_tokens":9}},"status":{"code":0, "message": "ok"}}
data:{"data":{"id":"123456789012345","choices":[{"delta":"test","finish_reason":"","index": 0,"role":"assistant"}],"usage":{"prompt_tokens":6,"knowledge_tokens": 0,"completion_tokens":4,"total_tokens":10}},"status":{"code":0, "message": "ok"}}
data:{"data":{"id":"123456789012345","choices":[{"delta":"!","finish_reason":"","index": 0,"role":"assistant"}],"usage":{"prompt_tokens":6,"knowledge_tokens": 0,"completion_tokens":5,"total_tokens":11}},"status":{"code":0, "message": "ok"}}
data:{"data":{"id":"123456789012345","choices":[{"delta":"","finish_reason":"stop","index": 0,"role":"assistant"}],"usage":{"prompt_tokens":6,"knowledge_tokens": 0,"completion_tokens":6,"total_tokens":13}},"status":{"code":0, "message": "ok"}}
data:[DONE]
- Non-Streaming
{
"data": {
"id": "4b44cd86cd2c000",
"choices": [
{
"message": "This is a test!",
"finish_reason": "stop",
"index": 0,
"role": "string"
}
],
"usage": {
"prompt_tokens": 6,
"knowledge_tokens": 0,
"completion_tokens": 6,
"total_tokens": 12
}
}
}
Error Information
Refer to Error Codes