Skip to main content

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 of max_new_tokens) must be <= the model's maximum context length (for different models' context length support, refer to Model List).

NameTypeRequiredDefaultOptional ValuesDescription
modelstringYes-Refer to Model ListModel ID
messagesobject[]Yes--Dialogue context input to the model, each object in the array represents a piece of chat context
max_new_tokensintNo1024[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_penaltyfloatNo1.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]
streambooleanNofalseEnable: 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]
temperaturefloatNo0.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_pfloatNo0.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
userstringNo--External user ID, application developers can pass in the application system user ID for tracking
  • messages section parameters:
NameTypeRequiredDefaultOptional ValuesDescription
rolestringYes-Enum values
user
assistant
system
Role of the message author, enum values. Note that the last item in the array must be user
contentobject[]Yes--Content of the message
  • content text section, can be plural, parameters are as follows:
NameTypeRequiredDefaultOptional ValuesDescription
typestringYestext-Message content type
textstringYes--Text content
  • content image part, can be plural, choose one of the following formats, different image information can choose different parameter formats, parameters are as follows:
NameTypeRequiredDefaultOptional ValuesDescription
typestringYesimage_url-Message content type
image_urlstringYes--Image URL
NameTypeRequiredDefaultOptional ValuesDescription
typestringYesimage_file_id-Message content type
image_file_idstringYes--File ID of the image uploaded via the file management interface
NameTypeRequiredDefaultOptional ValuesDescription
typestringYesimage_base64-Message content type
image_base64stringYes--Base64 encoded content of the image
  • content video part, can only be singular, choose one of the following formats, cannot coexist with image part, parameters are as follows:
NameTypeRequiredDefaultOptionsDescription
typestringYesvideo_url-Message content type
video_urlstringYes--Video file URL
NameTypeRequiredDefaultOptionsDescription
typestringYesvideo_file_id-Message content type
video_file_idstringYes--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

NameTypeDescription
dataobjectGenerated content
  • data section parameters:
NameTypeDescription
idstringMessage ID
choicesobject[]List of generated responses
usageobjectToken usage
  • choices section parameters:
NameTypeDescription
messagestringGenerated response content for non-streaming requests
finish_reasonstringReason 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
indexintIndex of the generated response
rolestringRole of the response message
deltastringGenerated response content for streaming requests
  • usage section parameters:
NameTypeDescription
prompt_tokensintNumber of tokens in user input
knowledge_tokensintNumber of tokens for knowledge base content input to the model (non-zero only if knowledge base is used and content is retrieved)
completion_tokensintNumber of tokens for generated message
total_tokensintTotal 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