vercel/ai · error · InvalidArgumentError
DeepSeek filenames must not exceed ${MAX_FILENAME_LENGTH} ch
Error message
DeepSeek filenames must not exceed ${MAX_FILENAME_LENGTH} characters. Received ${filenameLength} characters. What it means
DeepSeek enforces a maximum filename length (MAX_FILENAME_LENGTH). The length is counted in Unicode code points (Array.from(filename).length, not UTF-8 bytes) and an over-long filename throws InvalidArgumentError for argument 'filename' before any network call.
Source
Thrown at packages/deepseek/src/files/deepseek-files.ts:167
fileBytes: Uint8Array;
mediaType: string;
filename: string | undefined;
}) {
if (fileBytes.length > MAX_FILE_SIZE_BYTES) {
throw new InvalidArgumentError({
argument: 'data',
message:
`DeepSeek file uploads must not exceed 64 MiB ` +
`(${MAX_FILE_SIZE_BYTES.toLocaleString('en-US')} bytes). ` +
`Received ${fileBytes.length.toLocaleString('en-US')} bytes.`,
});
}
if (filename != null) {
const filenameLength = Array.from(filename).length;
if (filenameLength > MAX_FILENAME_LENGTH) {
throw new InvalidArgumentError({
argument: 'filename',
message:
`DeepSeek filenames must not exceed ${MAX_FILENAME_LENGTH} characters. ` +
`Received ${filenameLength} characters.`,
});
}
}
const normalizedMediaType = normalizeMediaType(mediaType);
const detectedMediaType = detectMediaType({ data: fileBytes });
if (
detectedMediaType != null &&
!supportedMediaTypes.has(detectedMediaType)
) {
throw new InvalidArgumentError({
argument: 'data',
message:View on GitHub (pinned to 69428b1f8b)
Solutions
- Truncate the filename (keeping the extension) before uploading.
- Generate a short synthetic filename (e.g. 'upload-<hash8>.png') when the original name is very long.
- Sanitize inputs: strip directory paths and limit the name length to the documented max.
Example fix
// before
await files.upload({ data, mediaType: 'image/png', filename: veryLongName });
// after
const base = veryLongName.split('/').pop() ?? 'file.png';
const filename = base.length > 128 ? base.slice(0, 100) + base.slice(base.lastIndexOf('.')) : base;
await files.upload({ data, mediaType: 'image/png', filename }); Defensive patterns
Strategy: validation
Validate before calling
if (filename && Array.from(filename).length > 128) {
filename = filename.slice(0, 100) + (filename.match(/\.[a-z0-9]+$/i)?.[0] ?? '');
} Try / catch
import { InvalidArgumentError } from '@ai-sdk/provider';
try {
await files.upload({ data, mediaType, filename });
} catch (e) {
if (InvalidArgumentError.isInstance(e) && e.argument === 'filename') {
await files.upload({ data, mediaType, filename: truncateName(filename) });
} else throw e;
} Prevention
- Strip paths and generate short names server-side instead of trusting client filenames.
- Count length in code points (Array.from), matching the library's check.
- Sanitize filenames in a shared upload utility used by all call sites.
When it happens
Trigger: Uploading a file whose filename string exceeds MAX_FILENAME_LENGTH code points via deepseek.files.upload with a filename provided.
Common situations: Passing long auto-generated names (timestamps + hashes + descriptions), or forwarding the full path or data-URI as the filename instead of the basename.
Related errors
- DeepSeek file uploads support JPEG, PNG, GIF, and WebP image
- DeepSeek file uploads must not exceed 64 MiB (67108864 bytes
- DeepSeek file uploads support JPEG, PNG, GIF, and WebP image
- DeepSeek file uploads support JPEG, PNG, GIF, and WebP image
- maxEmbeddingsPerCall must be greater than 0
AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30).
Data as JSON: /api/errors/ce8295bab33e0412.
Report an issue: GitHub.