vercel/ai · error · InvalidPromptError
DeepSeek image URLs must not exceed 8192 characters.
Error message
DeepSeek image URLs must not exceed 8192 characters.
What it means
DeepSeek rejects image URLs longer than 8192 characters. The SDK proactively validates URL-typed image parts in convertToDeepSeekChatMessages and throws InvalidPromptError before any network call when part.data.url.toString().length > 8192.
Source
Thrown at packages/deepseek/src/chat/convert-to-deepseek-chat-messages.ts:185
provider: 'deepseek',
}),
});
} else if (part.data.type === 'url' || part.data.type === 'data') {
const resolvedMediaType = resolveFullMediaType({ part });
if (!supportedImageMediaTypes.has(resolvedMediaType)) {
throw new UnsupportedFunctionalityError({
functionality: `DeepSeek image media type ${resolvedMediaType}`,
message:
'DeepSeek supports JPEG, PNG, GIF, and WebP image inputs.',
});
}
if (part.data.type === 'url') {
const url = part.data.url.toString();
if (url.length > 8192) {
throw new InvalidPromptError({
prompt,
message:
'DeepSeek image URLs must not exceed 8192 characters.',
});
}
if (filePartOptions?.fileData === true) {
throw new InvalidPromptError({
prompt,
message:
'DeepSeek `fileData` image parts require inline data, not a URL.',
});
}
userContent.push({
type: 'image_url',
image_url: {
url,View on GitHub (pinned to 69428b1f8b)
Solutions
- Shorten the URL — host the image at a stable short URL
- If the content is base64, pass it as inline data (a Uint8Array/binary data part) instead of a data: URL
- Reduce query-string size (e.g. presign with fewer parameters or a shorter expiry encoding)
Example fix
// before
{ type: 'image', image: 'data:image/png;base64,' + veryLongBase64 }
// after
{ type: 'image', image: await fetch(url).then(r => new Uint8Array(await r.arrayBuffer())) } Defensive patterns
Strategy: validation
Validate before calling
function assertImageUrlLength(part) {
const url = typeof part.image === 'string' || part.image instanceof URL ? part.image.toString() : null;
if (url && url.length > 8192) throw new Error('DeepSeek image URL exceeds 8192 chars; use inline data instead');
} Try / catch
try { await generateText(...); } catch (e) { if (InvalidPromptError.isInstance(e) && /8192/.test(e.message)) { /* switch to binary data part */ } throw e; } Prevention
- Never pass data: URLs as image URLs to DeepSeek — use Uint8Array data parts
- Keep presigned URLs short; strip unnecessary query params
- Validate URL length in prompt-assembly code
When it happens
Trigger: Sending an image part of type 'url' whose URL string exceeds 8192 characters — typically data: URLs passed as URLs, or very long signed/CDN URLs with huge query strings.
Common situations: Encoding base64 data as a data: URL instead of passing Uint8Array data directly; presigned S3 URLs with long tokens; appending large transform parameters to image CDN URLs.
Related errors
- DeepSeek image media type ${resolvedMediaType}
- DeepSeek `fileData` image parts require inline data, not a U
- DeepSeek `imageDetail` cannot be combined with `fileData`.
- Unsupported image mime type: ${mimeType}, expected one of: $
- DeepSeek assistant prefix completion requires `prefix: true`
AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30).
Data as JSON: /api/errors/995ce8849379bda9.
Report an issue: GitHub.