vercel/ai · error · Error

The provider does not support file uploads. Make sure it exp

Error message

The provider does not support file uploads. Make sure it exposes a files() method.

What it means

uploadFile (packages/ai/src/upload-file/upload-file.ts:70) resolves a FilesV4 API from the provider: it uses `api.uploadFile` directly if present, otherwise calls `api.files()`. If the provider object has neither an `uploadFile` method nor a callable `files()` method, it throws this Error. The provider model in use simply doesn't implement the file-upload capability.

Source

Thrown at packages/ai/src/upload-file/upload-file.ts:70

  const data: FilesV4UploadFileCallOptions['data'] =
    dataArg instanceof Uint8Array || typeof dataArg === 'string'
      ? { type: 'data', data: dataArg }
      : dataArg;

  const mediaType =
    mediaTypeArg ??
    (data.type === 'text'
      ? 'text/plain'
      : (detectMediaType({ data: data.data }) ??
        (isLikelyText(data.data) ? 'text/plain' : 'application/octet-stream')));

  const filesApi: FilesV4 =
    'uploadFile' in api
      ? api
      : typeof api.files === 'function'
        ? api.files()
        : (() => {
            throw new Error(
              'The provider does not support file uploads. Make sure it exposes a files() method.',
            );
          })();

  const result = await filesApi.uploadFile({
    data,
    mediaType,
    filename,
    providerOptions,
  });

  return new DefaultUploadFileResult({
    providerReference: result.providerReference,
    mediaType: result.mediaType,
    filename: result.filename,
    providerMetadata: result.providerMetadata,
    warnings: result.warnings,
  });

View on GitHub (pinned to 69428b1f8b)

Solutions

  1. Pass the provider instance (e.g. `openai` itself), not a model or chat object — verify it exposes `files()`.
  2. Upgrade the provider package to a version implementing FilesV4 (files() / uploadFile support).
  3. Check `typeof provider.files === 'function'` before calling uploadFile and show a capability error otherwise.
  4. Use a different provider that supports file uploads if this one cannot.

Example fix

// before
await uploadFile({ api: openai('gpt-4o'), data }); // model, not provider
// after
await uploadFile({ api: openai, data }); // provider exposing files()
Defensive patterns

Strategy: type-guard

Validate before calling

function supportsFiles(api: unknown): api is { files(): FilesV4 } {
  return api != null &&
    (typeof (api as any).files === 'function' || 'uploadFile' in (api as any));
}
if (!supportsFiles(provider)) throw new Error('Provider does not support file uploads');

Type guard

function hasFilesApi(api: unknown): api is { files(): FilesV4 } | { uploadFile: FilesV4['uploadFile'] } {
  return typeof api === 'object' && api !== null &&
    ('uploadFile' in api || typeof (api as { files?: unknown }).files === 'function');
}

Try / catch

try {
  await uploadFile({ api: provider, data });
} catch (e) {
  if (e instanceof Error && e.message.includes('does not support file uploads')) {
    throw new Error(`${providerName} does not support file uploads; upgrade the provider package or choose another provider`);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling `uploadFile({ api: someProvider, data, ... })` with a provider instance that lacks a `files()` factory method and an `uploadFile` method — i.e. a provider that hasn't implemented FilesV4 support.

Common situations: Using a provider package/version that predates files() support; passing a model (LanguageModel) instead of the provider instance; passing the wrong provider object to uploadFile; older pinned versions of a provider SDK.

Related errors


AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30). Data as JSON: /api/errors/1d5f58500f12b25d. Report an issue: GitHub.