uploadFile

suspend fun DeepSeekClientBase.uploadFile(bytes: ByteArray, filename: String, expiresAfterSeconds: Int? = null): FileObject

Uploads an image for a vision model to read, and returns the stored FileObject.

The file is sent as multipart/form-data with purpose FilePurpose.USER_DATA. Its format is detected from the bytes themselves — JPEG, PNG, GIF and WebP are supported — so filename is only a label. The API caps an upload at 64 MiB.

Uploads use uploadTimeout rather than the client's default request timeout, since a large file on a slow link needs longer than a chat call.

Example:

val uploaded = client.uploadFile(imageBytes, "cat.jpg", expiresAfterSeconds = 3600)
client.chatCompletion {
params { model = ChatModel.DEEPSEEK_FLASH }
messages {
user {
text("What is in this image?")
imageFile(uploaded.id)
}
}
}

Return

The stored FileObject, whose id can be referenced from a chat message

Parameters

bytes

Raw file content; must not be empty

filename

Name to store the file under; must not be blank or contain a line break

expiresAfterSeconds

Lifetime of the file, anchored at its creation, between 3600 and 2592000 seconds. Left null, the file is kept indefinitely.

Throws

if bytes is empty, filename is unusable, or expiresAfterSeconds falls outside 3600..2592000

if the API returns a non-2xx status