DeepSeek-v4-flash-vision-exp
DeepSeek-v4-flash-vision-exp

原始链接: https://api-docs.deepseek.com/guides/vision/

`deepseek-v4-flash-vision-exp` 模型通过三种兼容 OpenAI 的输入方式支持图像分析(JPEG、PNG、GIF、WebP): 1. **Base64 编码:** 作为数据 URL 直接嵌入。 2. **外部 URL:** 公开可访问的 HTTP(S) 链接。 3. **文件 API (Files API):** 通过 `file_id` 引用,适用于大文件(最大 64 MiB)或重复使用。 **主要准则:** * **请求限制:** 内嵌图像计入 48 MiB 的请求体大小限制。对于较大文件或遇到请求限制时,请使用文件 API。 * **处理:** 图像会自动调整大小以保持 Token 使用的一致性(每张图像最多 384 个 Token)。对于 `image_url` 输入,可设置 `detail` 参数(`low`、`high`、`original`、`auto`)来控制质量与成本。 * **约束:** 图像仅限用于用户消息,且必须配合具备视觉能力的模型使用。 * **API 兼容性:** 除了标准的 OpenAI 风格格式外,该模型还支持兼容 Anthropic 的 `/messages` 端点和 Responses API,在这些接口中保持功能一致。 有关文件大小、尺寸和单次请求数量的具体限制,请参考官方 API 文档。

**DeepSeek-v4-flash-vision-exp** 的发布在 Hacker News 上引发了广泛讨论,标志着该模型终于加入了备受期待的视觉能力。 社区讨论的主要重点包括: * **技术限制**:该模型在推理时会将图像调整为 800x800 分辨率。虽然这限制了高保真细节的呈现,但用户建议可以通过使用“缩放”工具或对图像进行分块(裁剪)处理,在不丢失上下文的前提下维持分辨率。 * **性能表现**:早期反馈褒贬不一。一些用户在 UI/前端开发、OCR 和设计反馈循环中取得了成功,而另一些用户则报告称其在读取模拟时钟或识别特定地标等“陷阱”任务中表现不佳。支持者则认为,这些“陷阱”并非评估实验性闪电模型(flash model)的可靠基准。 * **智能体效用**:开发者认为视觉集成对于自主智能体循环至关重要,它使模型能够“看到”并纠正 UI 故障、验证生成的代码,或处理图表和示意图等视觉输入。 * **市场情绪**:许多用户认为这是一个至关重要的升级,使 DeepSeek 在与其他前沿模型的竞争中保持优势。关于该模型的权重是否会像 DeepSeek 此前惯例那样开源,目前仍存在持续的猜测。
相关文章

原文

The deepseek-v4-flash-vision-exp model accepts images alongside text, so you can ask the model to describe pictures, read text from screenshots, analyze charts, and more.

Supported image formats: JPEG, PNG, GIF, and WebP. The format is detected from the actual file content, not from the file name or the declared MIME type.


Sending Images​

There are three ways to provide an image to the model. All of them use the standard OpenAI-compatible Chat Completions format, where content is an array of blocks instead of a plain string. The same three methods are also available in the Responses API, where images are carried in input_image content parts.

The base_url for the examples below is https://api.deepseek.com.

1. Base64-encoded image (inline)​

Encode the image and embed it directly in the request as a data: URL. This is the simplest option for local files. The encoded data counts toward the 48 MiB request body limit (see Limits).

import base64
from openai import OpenAI

client = OpenAI(api_key="<DeepSeek API Key>", base_url="https://api.deepseek.com")

with open("image.jpg", "rb") as f:
b64 = base64.b64encode(f.read()).decode("utf-8")

response = client.chat.completions.create(
model="deepseek-v4-flash-vision-exp",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "What is in this image?"},
{
"type": "image_url",
"image_url": {"url": f"data:image/jpeg;base64,{b64}"},
},
],
}
],
)
print(response.choices[0].message.content)
curl https://api.deepseek.com/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <DeepSeek API Key>" \
-d '{
"model": "deepseek-v4-flash-vision-exp",
"messages": [
{
"role": "user",
"content": [
{"type": "text", "text": "What is in this image?"},
{"type": "image_url", "image_url": {"url": "data:image/jpeg;base64,<BASE64_DATA>"}}
]
}
]
}'

2. External image URL​

Pass a publicly accessible http(s) link and the model downloads the image for you. The URL must be at most 8192 characters, the image file may be at most 32 MiB, and the download must complete within 60 seconds. If your link is longer, use a base64 data URL or the Files API instead.

response = client.chat.completions.create(
model="deepseek-v4-flash-vision-exp",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "Describe this image."},
{
"type": "image_url",
"image_url": {"url": "https://example.com/image.jpg"},
},
],
}
],
)
print(response.choices[0].message.content)

3. Reference a file uploaded via the Files API​

Upload an image once with the Files API, then reference its file_id in your requests. This is the best option when you reuse the same image across multiple requests, or when the image pushes the request body over the 48 MiB inline limit. Unlike inline images, images referenced via Files API file_id may be up to 64 MiB and are not subject to the 32 MiB per-image check.

Use a file content block with the returned file_id (which has the form file-api-...):

response = client.chat.completions.create(
model="deepseek-v4-flash-vision-exp",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "What is in this image?"},
{"type": "file", "file_id": "file-api-xxxxxxxxxxxxxxxx"},
],
}
],
)
print(response.choices[0].message.content)

Alternatively, a file block can carry the image inline as base64 via file_data instead of file_id (the two are mutually exclusive):

{
"type": "file",
"file_data": "data:image/jpeg;base64,<BASE64_DATA>",
"filename": "image.jpg"
}

Detail Level​

For image_url inputs you can optionally set a detail field to control how the image is processed:

ValueBehavior
lowThe image is downscaled to 512×512 before inference. Faster and cheaper when fine visual detail is not important.
highKeeps the original image. (Provided for compatibility; equivalent to original.)
originalKeeps the original image.
autoAutomatic selection. Currently equivalent to original.
{
"type": "image_url",
"image_url": {"url": "https://example.com/image.jpg", "detail": "low"}
}

When to Use the Files API​

Inline images (base64 or file_data) count toward the request body size limit of 48 MiB. Consider the Files API when:

  • A single request would exceed the body size limit.
  • The image is larger than 32 MiB, which is only possible through the Files API.
  • You reference the same image in multiple requests and want to avoid re-uploading it each time.

Token Usage​

Images are converted into tokens based on their dimensions, and these tokens are billed together with your text tokens.

Before inference, every image is automatically resized:

  • Images with a total pixel count below roughly 384×384 are scaled up while preserving their aspect ratio.
  • Larger images are scaled down while preserving their aspect ratio, so that the total pixel count after resizing is roughly that of an 800×800 image.

As a result, there is an upper bound of 384 tokens per image: for example, a 2000×2000 image and a 5000×5000 image consume the same number of tokens after resizing. When a request contains multiple images, each image is counted independently under the same rule — there is no separate calculation for multi-image requests.

To estimate the token cost of an image of a specific size, use the image token calculator on the Token & Token Usage page.


LimitValue
Supported formatsJPEG, PNG, GIF, WebP
External URL length8192 characters
Request body size48 MiB
Max single image size (base64 / external URL)32 MiB
Max single image size (Files API file_id)64 MiB
Max images per request600
Max total image size per request64 MiB without file_id images; up to 200 MiB including file_id images
Max image dimension8192 px per side; drops to 4096 px per side when a request contains 15 or more images

For storage and upload quotas of files uploaded via the Files API, see Files API: Limits.


Restrictions​

  • Images are supported in user messages only: images in system or assistant messages return a 400 error.
  • Only vision models (deepseek-v4-flash-vision-exp) accept images; other models return a 400 error ("This model does not support image").
  • User text containing the reserved image placeholder token is rejected with a 400 error.

Using Images with the Anthropic API​

In addition to the OpenAI-compatible endpoint above, you can send images through the Anthropic-compatible /messages endpoint (base_url = https://api.deepseek.com/anthropic). For general setup, see Anthropic API.

The difference is the shape of the image content block. Instead of image_url, Anthropic uses an image block with a source object whose type is one of base64, url, or file:

import anthropic

client = anthropic.Anthropic()

message = client.messages.create(
model="deepseek-v4-flash-vision-exp",
max_tokens=1024,
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "What is in this image?"},
{
"type": "image",
"source": {
"type": "base64",
"media_type": "image/jpeg",
"data": "<BASE64_DATA>",
},
},
],
}
],
)
print(message.content)

The three source variants mirror the OpenAI methods above:

source.typeEquivalent OpenAI methodNotes
base64Base64-encoded imageRequires a media_type field (image/jpeg, image/png, image/gif, or image/webp).
urlExternal image URLMax 8192 characters.
fileFiles API file_idRequires the header anthropic-beta: files-api-2025-04-14.

Using Images with the Responses API​

The deepseek-v4-flash-vision-exp model also accepts images through the OpenAI-compatible Responses API. The same three input methods (base64 data URL, external http(s) URL, Files API file_id) and the same limits apply; only the content part shape differs — images are carried in input_image parts, either in user / developer messages or in the output of function_call_output / custom_tool_call_output items:

response = client.responses.create(
model="deepseek-v4-flash-vision-exp",
input=[
{
"role": "user",
"content": [
{"type": "input_text", "text": "What is in this image?"},
{"type": "input_image", "image_url": "https://example.com/image.jpg", "detail": "low"},
],
}
],
)
print(response.output_text)

The input_image part supports a detail field with the same semantics as above (low / high / original / auto). detail is ignored when the image is provided via file_id, and image_url and file_id are mutually exclusive.

For field semantics, restrictions (images in system / assistant messages are rejected with a 400 error), and tool-output images, see the Responses API guide.

联系我们 contact @ memedata.com