Messages with vision: DeepSeek V4 Flash Vision (Anthropic format)
curl --request POST \
--url https://api.apiyi.com/v1/messages \
--header 'Content-Type: application/json' \
--header 'anthropic-version: <anthropic-version>' \
--header 'x-api-key: <api-key>' \
--data '
{
"model": "deepseek-v4-flash-vision-exp",
"max_tokens": 800,
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "这张图里有什么?用一句话描述。"
},
{
"type": "image",
"source": {
"type": "url",
"url": "https://docs.apiyi.com/images/checks-passed.png"
}
}
]
}
]
}
'import requests
url = "https://api.apiyi.com/v1/messages"
payload = {
"model": "deepseek-v4-flash-vision-exp",
"max_tokens": 800,
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "这张图里有什么?用一句话描述。"
},
{
"type": "image",
"source": {
"type": "url",
"url": "https://docs.apiyi.com/images/checks-passed.png"
}
}
]
}
]
}
headers = {
"anthropic-version": "<anthropic-version>",
"x-api-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'anthropic-version': '<anthropic-version>',
'x-api-key': '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'deepseek-v4-flash-vision-exp',
max_tokens: 800,
messages: [
{
role: 'user',
content: [
{type: 'text', text: '这张图里有什么?用一句话描述。'},
{
type: 'image',
source: {type: 'url', url: 'https://docs.apiyi.com/images/checks-passed.png'}
}
]
}
]
})
};
fetch('https://api.apiyi.com/v1/messages', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.apiyi.com/v1/messages",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'deepseek-v4-flash-vision-exp',
'max_tokens' => 800,
'messages' => [
[
'role' => 'user',
'content' => [
[
'type' => 'text',
'text' => '这张图里有什么?用一句话描述。'
],
[
'type' => 'image',
'source' => [
'type' => 'url',
'url' => 'https://docs.apiyi.com/images/checks-passed.png'
]
]
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"anthropic-version: <anthropic-version>",
"x-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.apiyi.com/v1/messages"
payload := strings.NewReader("{\n \"model\": \"deepseek-v4-flash-vision-exp\",\n \"max_tokens\": 800,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": [\n {\n \"type\": \"text\",\n \"text\": \"这张图里有什么?用一句话描述。\"\n },\n {\n \"type\": \"image\",\n \"source\": {\n \"type\": \"url\",\n \"url\": \"https://docs.apiyi.com/images/checks-passed.png\"\n }\n }\n ]\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("anthropic-version", "<anthropic-version>")
req.Header.Add("x-api-key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.apiyi.com/v1/messages")
.header("anthropic-version", "<anthropic-version>")
.header("x-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"deepseek-v4-flash-vision-exp\",\n \"max_tokens\": 800,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": [\n {\n \"type\": \"text\",\n \"text\": \"这张图里有什么?用一句话描述。\"\n },\n {\n \"type\": \"image\",\n \"source\": {\n \"type\": \"url\",\n \"url\": \"https://docs.apiyi.com/images/checks-passed.png\"\n }\n }\n ]\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.apiyi.com/v1/messages")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["anthropic-version"] = '<anthropic-version>'
request["x-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"deepseek-v4-flash-vision-exp\",\n \"max_tokens\": 800,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": [\n {\n \"type\": \"text\",\n \"text\": \"这张图里有什么?用一句话描述。\"\n },\n {\n \"type\": \"image\",\n \"source\": {\n \"type\": \"url\",\n \"url\": \"https://docs.apiyi.com/images/checks-passed.png\"\n }\n }\n ]\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"id": "a5cb230d-ac08-43ed-8c4b-8f88b37119d3",
"type": "message",
"role": "assistant",
"model": "deepseek-v4-flash-vision-exp",
"content": [
{
"type": "text",
"text": "图中显示一条提示:所有检查均已通过,其中包含一次成功的 Mintlify 部署。"
}
],
"stop_reason": "end_turn",
"usage": {
"input_tokens": 295,
"output_tokens": 51,
"cache_creation_input_tokens": 0,
"cache_read_input_tokens": 0
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}DeepSeek V4 Flash Vision
DeepSeek V4 Flash Vision Messages API 參考
deepseek-v4-flash-vision-exp 的 Anthropic 原生 /v1/messages API 參考與線上除錯:base64 與外鏈兩種傳圖方式、思考開關、工具閉環,令牌必須用 ClaudeCode 分組。
POST
/
v1
/
messages
Messages with vision: DeepSeek V4 Flash Vision (Anthropic format)
curl --request POST \
--url https://api.apiyi.com/v1/messages \
--header 'Content-Type: application/json' \
--header 'anthropic-version: <anthropic-version>' \
--header 'x-api-key: <api-key>' \
--data '
{
"model": "deepseek-v4-flash-vision-exp",
"max_tokens": 800,
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "这张图里有什么?用一句话描述。"
},
{
"type": "image",
"source": {
"type": "url",
"url": "https://docs.apiyi.com/images/checks-passed.png"
}
}
]
}
]
}
'import requests
url = "https://api.apiyi.com/v1/messages"
payload = {
"model": "deepseek-v4-flash-vision-exp",
"max_tokens": 800,
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "这张图里有什么?用一句话描述。"
},
{
"type": "image",
"source": {
"type": "url",
"url": "https://docs.apiyi.com/images/checks-passed.png"
}
}
]
}
]
}
headers = {
"anthropic-version": "<anthropic-version>",
"x-api-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'anthropic-version': '<anthropic-version>',
'x-api-key': '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'deepseek-v4-flash-vision-exp',
max_tokens: 800,
messages: [
{
role: 'user',
content: [
{type: 'text', text: '这张图里有什么?用一句话描述。'},
{
type: 'image',
source: {type: 'url', url: 'https://docs.apiyi.com/images/checks-passed.png'}
}
]
}
]
})
};
fetch('https://api.apiyi.com/v1/messages', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.apiyi.com/v1/messages",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'deepseek-v4-flash-vision-exp',
'max_tokens' => 800,
'messages' => [
[
'role' => 'user',
'content' => [
[
'type' => 'text',
'text' => '这张图里有什么?用一句话描述。'
],
[
'type' => 'image',
'source' => [
'type' => 'url',
'url' => 'https://docs.apiyi.com/images/checks-passed.png'
]
]
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"anthropic-version: <anthropic-version>",
"x-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.apiyi.com/v1/messages"
payload := strings.NewReader("{\n \"model\": \"deepseek-v4-flash-vision-exp\",\n \"max_tokens\": 800,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": [\n {\n \"type\": \"text\",\n \"text\": \"这张图里有什么?用一句话描述。\"\n },\n {\n \"type\": \"image\",\n \"source\": {\n \"type\": \"url\",\n \"url\": \"https://docs.apiyi.com/images/checks-passed.png\"\n }\n }\n ]\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("anthropic-version", "<anthropic-version>")
req.Header.Add("x-api-key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.apiyi.com/v1/messages")
.header("anthropic-version", "<anthropic-version>")
.header("x-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"deepseek-v4-flash-vision-exp\",\n \"max_tokens\": 800,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": [\n {\n \"type\": \"text\",\n \"text\": \"这张图里有什么?用一句话描述。\"\n },\n {\n \"type\": \"image\",\n \"source\": {\n \"type\": \"url\",\n \"url\": \"https://docs.apiyi.com/images/checks-passed.png\"\n }\n }\n ]\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.apiyi.com/v1/messages")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["anthropic-version"] = '<anthropic-version>'
request["x-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"deepseek-v4-flash-vision-exp\",\n \"max_tokens\": 800,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": [\n {\n \"type\": \"text\",\n \"text\": \"这张图里有什么?用一句话描述。\"\n },\n {\n \"type\": \"image\",\n \"source\": {\n \"type\": \"url\",\n \"url\": \"https://docs.apiyi.com/images/checks-passed.png\"\n }\n }\n ]\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"id": "a5cb230d-ac08-43ed-8c4b-8f88b37119d3",
"type": "message",
"role": "assistant",
"model": "deepseek-v4-flash-vision-exp",
"content": [
{
"type": "text",
"text": "图中显示一条提示:所有检查均已通过,其中包含一次成功的 Mintlify 部署。"
}
],
"stop_reason": "end_turn",
"usage": {
"input_tokens": 295,
"output_tokens": 51,
"cache_creation_input_tokens": 0,
"cache_read_input_tokens": 0
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}這個端點的令牌必須是
ClaudeCode 分組,這是硬要求。用 default 分組會撞上兩個疊加問題:- 不顯式傳
top_p一律返回 400Invalid top_p value - 就算補上
top_p,把第一輪返回的thinking塊原樣回傳到第二輪會報unknown variant 'thinking', expected one of 'text', 'image_url', 'file'—— 而 Claude Code、Anthropic SDK 這類標準客戶端一定會原樣回傳,所以多輪必斷
ClaudeCode 分組,兩個問題都不存在。OpenAI 格式請改用
Chat 線上除錯。右側 Playground 可直接除錯:在 x-api-key 填
sk-your-apiyi-key(ClaudeCode 分組的令牌,
不帶 Bearer 字首),anthropic-version 保持 2023-06-01。
預設示例用的是一張公網圖片、並已關閉深度思考,點擊發送即可看到響應。引數說明速查
| 引數 | 型別 | 必填 | 預設 | 說明 |
|---|---|---|---|---|
model | string | ✓ | — | 固定 deepseek-v4-flash-vision-exp |
max_tokens | int | ✓ | — | Anthropic 格式下必填,硬上限 393,216;開思考建議 2000+ |
messages | array | ✓ | — | content 可以是字串,也可以是內容塊陣列 |
system | string | — | 系統提示詞 | |
thinking.type | string | enabled | disabled 可關閉,關掉後 content 只剩 text 塊 | |
thinking.budget_tokens | int | — | enabled 時的思考預算 | |
stream | bool | false | SSE 流式,標準 Anthropic 事件序列 | |
top_p | number | — | ClaudeCode 分組下可省略 | |
temperature / top_k / stop_sequences | — | — | 均生效 | |
tools | array | — | Anthropic 標準 input_schema 格式 |
兩種傳圖方式
source.type = "base64"
{
"type": "image",
"source": {
"type": "base64",
"media_type": "image/jpeg",
"data": "<BASE64>"
}
}
data 不含 data:image/jpeg;base64, 字首(這一點和 OpenAI 格式不同)。
source.type = "url"
{
"type": "image",
"source": {"type": "url", "url": "https://example.com/image.jpg"}
}
source.type = "url" 只有 ClaudeCode 分組支援,default 分組會報
You have uploaded an unsupported image。source.type = "file" 需要 Files API,本平臺不提供。響應的 content 是塊陣列
| 情況 | content |
|---|---|
| 預設(思考開啟) | [{"type": "thinking", ...}, {"type": "text", ...}] |
thinking.type = "disabled" | [{"type": "text", ...}] |
| 呼叫工具時 | [{"type": "thinking", ...}, {"type": "tool_use", ...}] |
ClaudeCode 分組返回的 thinking 塊帶 signature 欄位,流式下也有 signature_delta。
多輪與工具閉環
把上一輪 assistant 的整個content(含 thinking 塊,不要剝)原樣放回 messages,
再追加 tool_result 即可:
{
"model": "deepseek-v4-flash-vision-exp",
"max_tokens": 1500,
"tools": [{
"name": "record_shape",
"input_schema": {
"type": "object",
"properties": {
"shape": {"type": "string"},
"color": {"type": "string"}
},
"required": ["shape", "color"]
}
}],
"messages": [
{"role": "user", "content": [
{"type": "text", "text": "看圖,呼叫 record_shape。"},
{"type": "image", "source": {"type": "url", "url": "https://example.com/shape.jpg"}}
]},
{"role": "assistant", "content": "<上一輪返回的 content 陣列,原樣放這裡>"},
{"role": "user", "content": [
{"type": "tool_result", "tool_use_id": "<上一輪 tool_use 的 id>", "content": "{\"ok\":true}"}
]}
]
}
default 分組會 400 的地方,也是 Claude Code 等客戶端
的必經路徑 —— 所以分組不能選錯。
快取欄位的口徑
自動字首快取生效,對映到 Anthropic 標準欄位:| 欄位 | 行為 |
|---|---|
cache_read_input_tokens | 自動字首快取命中量。命中範圍止於第一張圖片之前,圖片本身永不進快取 |
cache_creation_input_tokens | 恆為 0。上游用的是自動字首快取,cache_control 顯式標記不生效 |
input_tokens | 命中後只剩未命中部分,與 OpenAI 格式的 prompt_tokens(始終全量)口徑不同,不能直接對賬 |
常見報錯
| 報錯 | 原因 |
|---|---|
Invalid top_p value, the valid range of top_p is (0, 1.0] | 用了 default 分組且沒傳 top_p,換 ClaudeCode 分組 |
unknown variant 'thinking' | 用了 default 分組且回傳了 thinking 塊,換 ClaudeCode 分組 |
You have uploaded an unsupported image | 格式不支援,或用了 default 分組 + source.type = "url" |
Image in assistant message is unsupported | 圖片只能放在 user 訊息裡 |
image file size exceeds limit 32 MB | 單圖超過 32 MiB |
授權
API易令牌,直接填 sk- 开头的 Key。分组必须为 ClaudeCode
標頭
Anthropic API 版本号,固定 2023-06-01
主體
application/json
模型 ID,固定 deepseek-v4-flash-vision-exp
可用選項:
deepseek-v4-flash-vision-exp 最大输出 tokens(Anthropic 格式下必填),硬上限 393,216。开思考建议 2000 以上
必填範圍:
x <= 393216消息数组。content 可以是字符串,也可以是内容块数组(图文混合)
Show child attributes
Show child attributes
系统提示词
深度思考开关。传 {"type": "disabled"} 关闭后 content 只剩 text 块,本端点两个分组都生效
Show child attributes
Show child attributes
是否流式输出(SSE)。事件为 Anthropic 标准的 message_start / content_block_delta / message_stop 等
采样温度
核采样阈值。ClaudeCode 分组下可省略;default 分组下不传必返回 400
候选截断
停止序列
工具列表,Anthropic 标准 input_schema 格式。实测含流式增量拼装与完整两轮闭环
這個頁面有幫助嗎?
⌘I