ai icon indicating copy to clipboard operation
ai copied to clipboard

File not supported - @ai-sdk/azure - v5 beta

Open arthberman opened this issue 1 year ago โ€ข 24 comments

Description

Summary

When attempting to upload a .txt file (with MIME type text/plain) using @ai-sdk/azure (ai v5), I receive an error indicating that this file type is not supported, even though the Azure OpenAI documentation lists text/plain as a supported MIME type.

Error

Error [AI_UnsupportedFunctionalityError]: 'file part media type text/plain' functionality not supported.
    at <unknown> (.next/server/chunks/4744.js:1:42683)
    at Array.map (<anonymous>)
    at prompt (.next/server/chunks/4744.js:1:41594)
    at h.getArgs (.next/server/chunks/4744.js:1:43350)
    at async h.doStream (.next/server/chunks/4744.js:1:48893)
    at async fn (.next/server/chunks/9464.js:33:48102)
    at async (.next/server/chunks/9464.js:33:3017)
    at async tw (.next/server/chunks/9464.js:33:898) {
  cause: undefined,
  functionality: 'file part media type text/plain'
]

Reproduction Steps

  1. Use @ai-sdk/azure (ai v5) to upload a .txt file.
  2. Observe the error above.

Expected Behavior

.txt files with MIME type text/plain should be accepted, as per Azure OpenAI documentation.

Actual Behavior

The SDK throws an AI_UnsupportedFunctionalityError for text/plain files.

Additional Information

AI SDK Version

"@ai-sdk/azure": "2.0.0-beta.1" "ai": "5.0.0-beta.1"

arthberman avatar Jun 26 '25 09:06 arthberman

To add some additional context:
It seems that the issue also occurs with other types of files (image, pdf etc).

arthberman avatar Jun 26 '25 10:06 arthberman

fyi: the issue still exists with beta3

arthberman avatar Jul 01 '25 08:07 arthberman

will look into this soon

dancer avatar Jul 01 '25 08:07 dancer

I also have this problem!!! +1

chrisdadev13 avatar Jul 04 '25 16:07 chrisdadev13

up :)

arthberman avatar Jul 14 '25 16:07 arthberman

Related: https://github.com/vercel/ai/issues/7399

niels-bosman avatar Jul 18 '25 11:07 niels-bosman

Might be because of that text file isn't included in supportedUrls property in the OpenAI provider's OpenAIChatLanguageModel class:

export class OpenAIChatLanguageModel implements LanguageModelV2 {
  readonly specificationVersion = 'v2';

  readonly modelId: OpenAIChatModelId;

  readonly supportedUrls = {
    'image/*': [/^https?:\/\/.*$/],
  };
  ...

Since Azure provider directly references OpenAIChatLanguageModel, this may why it isn't supported. (I come across a similar issue for image file type when migrating a community provider.)

Xiang-CH avatar Jul 22 '25 10:07 Xiang-CH

Seeing a similar issue trying to perform generateText and generateObject completions with an mp3 file in the user message.

    "@ai-sdk/openai": "^2.0.0",
    "ai": "^5.0.0",

Here's a script that reproduces for me. Roughly the same completion with the same model works when using ai sdk v4 (although the message format is slightly different between v4 and v5).

import * as dotenv from 'dotenv';

const envPath = process.argv[2] || '.env.development';
console.log(`Loading environment from: ${envPath}`);
dotenv.config({ path: envPath });

import * as fs from 'fs';
import * as path from 'path';
import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';

async function testOpenAIGPT4oWithAudio(): Promise<void> {
  try {
    console.log('๐ŸŽต Testing OpenAI GPT-4o Audio Preview with audio input...\n');

    // Check if the audio file exists
    const audioFilePath = path.join(process.cwd(), 'audio-sample.mp3');

    if (!fs.existsSync(audioFilePath)) {
      console.error(`โŒ Audio file not found: ${audioFilePath}`);
      throw new Error(`Audio file not found: ${audioFilePath}`);
    }

    console.log(`๐Ÿ“ Found audio file: ${audioFilePath}`);

    // Read the audio file
    const audioBuffer = fs.readFileSync(audioFilePath);
    console.log(`๐Ÿ“Š Audio file size: ${audioBuffer.length} bytes`);

    const model = openai('gpt-4o-audio-preview-2025-06-03');

    const result = await generateText({
      model,
      messages: [
        {
          role: 'user',

          content: [
            {
              type: 'text',
              text: 'Tell me what this audio is about.',
            },
            {
              type: 'file',
              data: audioBuffer,
              mediaType: 'audio/mpeg'
            },
          ]
        },
      ],
      temperature: 0.3,
    });

    console.log(`Response: ${result.text}`);

    // Display usage information if available
    if (result.usage) {
      console.log('\n๐Ÿ“Š USAGE STATS:');
      console.log(`- Prompt tokens: ${result.usage.inputTokens}`);
      console.log(`- Completion tokens: ${result.usage.outputTokens}`);
      console.log(`- Total tokens: ${result.usage.totalTokens}`);
    }

    console.log('\n๐ŸŽ‰ Test completed successfully!');

  } catch (error) {
    console.error('โŒ Error testing GPT-4o with audio:', error);

    if (error instanceof Error) {
      console.error('Error message:', error.message);
      console.error('Error stack:', error.stack);
    }

    throw error;
  }
}

async function main(): Promise<void> {
  console.log('๐Ÿงช OpenAI GPT-4o Audio Processing Test');
  console.log('======================================\n');

  await testOpenAIGPT4oWithAudio();
}

main()
  .then(() => {
    console.log('Script completed successfully');
    process.exit(0);
  })
  .catch((error) => {
    console.error('โŒ Script failed:', error);
    process.exit(1);
  });

Error

AI_UnsupportedFunctionalityError: 'file part media type audio/mpeg' functionality not supported.
    at <anonymous> (./node_modules/@ai-sdk/openai/src/responses/convert-to-openai-responses-messages.ts:94:25)
    at Array.map (<anonymous>)
    at convertToOpenAIResponsesMessages (./node_modules/@ai-sdk/openai/src/responses/convert-to-openai-responses-messages.ts:58:28)
    at OpenAIResponsesLanguageModel.getArgs (./node_modules/@ai-sdk/openai/src/responses/openai-responses-language-model.ts:92:13)
    at OpenAIResponsesLanguageModel.doGenerate (./node_modules/@ai-sdk/openai/src/responses/openai-responses-language-model.ts:247:49)
    at fn (./node_modules/ai/src/generate-text/generate-text.ts:359:48)
    at <anonymous> (./node_modules/ai/src/telemetry/record-span.ts:18:28)
    at Object.startActiveSpan (./node_modules/ai/src/telemetry/noop-tracer.ts:21:14)
    at recordSpan (./node_modules/ai/src/telemetry/record-span.ts:16:17)
    at <anonymous> (./node_modules/ai/src/generate-text/generate-text.ts:316:13)

alexchao avatar Aug 02 '25 10:08 alexchao

I am also experiencing similar error for PDF files as signed URLs using AI SDK v5, AI Gateway with GPT-4o.

Error: AI_UnsupportedFunctionalityError PDF file parts with URLs' functionality not supported.

Seems pretty high-priority since we can't send more than 4.5MB as data URI due to vercel functions data payload limitations.

cc: @dancer

rohan-dave avatar Aug 15 '25 10:08 rohan-dave

@dancer Any updates on this? This is blocking us pretty hard.

For internal reasons, we're only able to use Azure's OpenAI models. Using OpenAI directly is not an option for us, sadly.

JoeRoddy avatar Aug 22 '25 15:08 JoeRoddy

@dancer Blocking us as well.

cloudycotton avatar Sep 07 '25 17:09 cloudycotton

Thanks @alexchao for a reproduction, but you are using the OpenAI provider, this issue is about @ai-sdk/azure. Feel free to open a separate bug if it still persists.

@arthberman if you or someone else could provide a minimal code snippet that reproduces the problem, it will be much easier for us to prioritize or for someone from the community to send a PR

gr2m avatar Sep 07 '25 22:09 gr2m

@gr2m I just worked on a migration to v5 from using the OpenAI provider directly and was disappointed to see such a core feature not supported. Would love to do what I can to help get this patched. Seeing the unsupported error for both pdfs and plain files, but I'm sure its the case for other file types too.

Minimal Reproduction:

index.ts

import { createAzure } from "@ai-sdk/azure";
import { generateText } from "ai";
import dotenv from "dotenv";
dotenv.config();

async function reproduceAzureBug() {
  const azure = createAzure({
    resourceName: process.env.AZURE_RESOURCE_NAME,
    apiKey: process.env.AZURE_API_KEY,
  });

  try {
    const result = await generateText({
      model: azure("gpt-5"),
      messages: [
        {
          role: "user",
          content: [
            {
              type: "text",
              text: "Hello, this is a test message for bug reproduction.",
            },
            {
              type: "file",
              mediaType: "text/plain",
              data: "Text content",
            },
            // Also causes an error
            // {
            //   type: "file",
            //   mediaType: "application/pdf",
            //   data: new URL(
            //     "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
            //   ),
            // },
          ],
        },
      ],
    });

    console.log("Response:", result.text);
  } catch (error) {
    console.error("Error occurred:", error);
    console.error("Error details:", JSON.stringify(error, null, 2));
  }
}

reproduceAzureBug();

package.json

{
  "name": "vercel-repro",
  "version": "1.0.0",
  "description": "",
  "main": "index.ts",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@ai-sdk/azure": "^2.0.28",
    "ai": "^5.0.40",
    "dotenv": "^17.2.2"
  },
  "devDependencies": {
    "@types/node": "^24.3.1",
    "typescript": "^5.9.2"
  }
}

.env

AZURE_RESOURCE_NAME=
AZURE_API_KEY=

package-lock.json

Command to run

npx ts-node index.ts

Error Reproduced

For the Plain Text

Error occurred: UnsupportedFunctionalityError [AI_UnsupportedFunctionalityError]: 'file part media type text/plain' functionality not supported.
    at file:///Users/andrew/Documents/poka/repos/vercel-repro/node_modules/@ai-sdk/openai/src/chat/convert-to-openai-chat-messages.ts:136:25
    at Array.map (<anonymous>)
    at convertToOpenAIChatMessages (file:///Users/andrew/Documents/poka/repos/vercel-repro/node_modules/@ai-sdk/openai/src/chat/convert-to-openai-chat-messages.ts:59:28)
    at OpenAIChatLanguageModel.getArgs (file:///Users/andrew/Documents/poka/repos/vercel-repro/node_modules/@ai-sdk/openai/src/chat/openai-chat-language-model.ts:111:53)
    at async OpenAIChatLanguageModel.doGenerate (file:///Users/andrew/Documents/poka/repos/vercel-repro/node_modules/@ai-sdk/openai/src/chat/openai-chat-language-model.ts:314:38)
    at async fn (file:///Users/andrew/Documents/poka/repos/vercel-repro/node_modules/ai/src/generate-text/generate-text.ts:382:32)
    at async file:///Users/andrew/Documents/poka/repos/vercel-repro/node_modules/ai/src/telemetry/record-span.ts:18:22
    at async _retryWithExponentialBackoff (file:///Users/andrew/Documents/poka/repos/vercel-repro/node_modules/ai/src/util/retry-with-exponential-backoff.ts:96:12) {
  cause: undefined,
  functionality: 'file part media type text/plain',
  [Symbol(vercel.ai.error)]: true,
  [Symbol(vercel.ai.error.AI_UnsupportedFunctionalityError)]: true
}
Error details: {
  "name": "AI_UnsupportedFunctionalityError",
  "functionality": "file part media type text/plain"
}

For the PDF

[[email protected]] injecting env (2) from .env -- tip: ๐Ÿ“ก version env with Radar: https://dotenvx.com/radar
(node:72725) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///Users/andrew/Documents/poka/repos/vercel-repro/index.ts is not specified and it doesn't parse as CommonJS.
Reparsing as ES module because module syntax was detected. This incurs a performance overhead.
To eliminate this warning, add "type": "module" to /Users/andrew/Documents/poka/repos/vercel-repro/package.json.
(Use `node --trace-warnings ...` to show where the warning was created)
Error occurred: APICallError [AI_APICallError]: Invalid Value: 'file'. This model does not support file content types.
    at file:///Users/andrew/Documents/poka/repos/vercel-repro/node_modules/@ai-sdk/provider-utils/src/response-handler.ts:56:16
    at processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async postToApi (file:///Users/andrew/Documents/poka/repos/vercel-repro/node_modules/@ai-sdk/provider-utils/src/post-to-api.ts:112:28)
    at async OpenAIChatLanguageModel.doGenerate (file:///Users/andrew/Documents/poka/repos/vercel-repro/node_modules/@ai-sdk/openai/src/chat/openai-chat-language-model.ts:320:9)
    at async fn (file:///Users/andrew/Documents/poka/repos/vercel-repro/node_modules/ai/src/generate-text/generate-text.ts:382:32)
    at async file:///Users/andrew/Documents/poka/repos/vercel-repro/node_modules/ai/src/telemetry/record-span.ts:18:22
    at async _retryWithExponentialBackoff (file:///Users/andrew/Documents/poka/repos/vercel-repro/node_modules/ai/src/util/retry-with-exponential-backoff.ts:96:12)
    at async fn (file:///Users/andrew/Documents/poka/repos/vercel-repro/node_modules/ai/src/generate-text/generate-text.ts:338:34)
    at async file:///Users/andrew/Documents/poka/repos/vercel-repro/node_modules/ai/src/telemetry/record-span.ts:18:22
    at async generateText (file:///Users/andrew/Documents/poka/repos/vercel-repro/node_modules/ai/src/generate-text/generate-text.ts:274:12) {
  cause: undefined,
  url: 'https://poka-open-ai-resource.openai.azure.com/openai/v1/chat/completions?api-version=preview',
  requestBodyValues: {
....

arbass22 avatar Sep 11 '25 15:09 arbass22

Okay so after a bit more digging I have the following other info: (1) Looks like the Azure provider is a pretty thin wrapper on the OpenAi provider, which is problematic because the Azure Open AI service handles attachments differently according to this page, but haven't dug so much into that yet. (2) Bigger issue is that the OpenAI provider only enumerates a few types of allowed files and reject all other files, even if the underlaying model might support it. See here.. As of 2.0.28 the file type needs to match image/* audio/* or application/pdf, otherwise an error is thrown before even trying to hit the model.

  • One quick fix would be to loosen the check around (2) and try to make the API request and let the request fail if its truly unsupported, or update those checks to more closely match the actual model capabilities, but I imagine thats a bit like playing whackamole
  • ^ But this might only fix the OpenAi provider not the issues caused by (1). Fixing Azure would require a deeper understanding of the differences with how their hosted OpenAI models behave differently, which I know contain some other limitations right now (such as lack of support for web_search tool).

For now, I will likely have to go back to using the OpenAI provider directly to hope PDFs work (sorry to my Azure credits ๐Ÿ˜”) and pull the contents of the plain/text file into the the messages directly. Will also need to pull contents of CSVs and other files into the message directly.

arbass22 avatar Sep 11 '25 16:09 arbass22

I can reproduce the issues in version v5.0.51. The same issue appears for text/markdown and text/csv files when using the Azure Provider.

Then thin OpenAI wrapper also causes issues when trying to use the responses API with Azure models. It is not possible to activate websearch or the code interpreter. We are dependent on Azure unfortunately, so switching provider is not an option.

matthiasmoke avatar Sep 24 '25 11:09 matthiasmoke

Migrated my app to v5 (5.0.60) this weekend and found that attachment functionality no longer works due to this issue. With v4, OpenAI and Azure Open AI were accepting experimental_attachments with type text/plain. Now both fail with 'Error [AI_UnsupportedFunctionalityError]: 'file part media type text/plain' functionality not supported.'

Can't use v5 until this is resolved.

matt-abstractai avatar Oct 06 '25 09:10 matt-abstractai

I investigated this issue and tested with Azure/OpenAI API. The error occurs because OpenAI/Azure responses API only supports PDF files (not text/plain). openai file upload

According to Azure's documentation:

The SDK's error is correct.

Should we update the documentation to clarify which file types are compatible with which OpenAI/ Azure APIs?

@gr2m thoughts?

rahulbhadja avatar Oct 07 '25 16:10 rahulbhadja

@gr2m I just worked on a migration to v5 from using the OpenAI provider directly and was disappointed to see such a core feature not supported. Would love to do what I can to help get this patched. Seeing the unsupported error for both pdfs and plain files, but I'm sure its the case for other file types too.

Minimal Reproduction:

index.ts

import { createAzure } from "@ai-sdk/azure"; import { generateText } from "ai"; import dotenv from "dotenv"; dotenv.config();

async function reproduceAzureBug() { const azure = createAzure({ resourceName: process.env.AZURE_RESOURCE_NAME, apiKey: process.env.AZURE_API_KEY, });

try { const result = await generateText({ model: azure("gpt-5"), messages: [ { role: "user", content: [ { type: "text", text: "Hello, this is a test message for bug reproduction.", }, { type: "file", mediaType: "text/plain", data: "Text content", }, // Also causes an error // { // type: "file", // mediaType: "application/pdf", // data: new URL( // "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf" // ), // }, ], }, ], });

console.log("Response:", result.text);

} catch (error) { console.error("Error occurred:", error); console.error("Error details:", JSON.stringify(error, null, 2)); } }

reproduceAzureBug();

package.json

{ "name": "vercel-repro", "version": "1.0.0", "description": "", "main": "index.ts", "scripts": { "test": "echo "Error: no test specified" && exit 1" }, "author": "", "license": "ISC", "dependencies": { "@ai-sdk/azure": "^2.0.28", "ai": "^5.0.40", "dotenv": "^17.2.2" }, "devDependencies": { "@types/node": "^24.3.1", "typescript": "^5.9.2" } }

.env

AZURE_RESOURCE_NAME=
AZURE_API_KEY=

package-lock.json

Command to run

npx ts-node index.ts

Error Reproduced

For the Plain Text

Error occurred: UnsupportedFunctionalityError [AI_UnsupportedFunctionalityError]: 'file part media type text/plain' functionality not supported.
    at file:///Users/andrew/Documents/poka/repos/vercel-repro/node_modules/@ai-sdk/openai/src/chat/convert-to-openai-chat-messages.ts:136:25
    at Array.map (<anonymous>)
    at convertToOpenAIChatMessages (file:///Users/andrew/Documents/poka/repos/vercel-repro/node_modules/@ai-sdk/openai/src/chat/convert-to-openai-chat-messages.ts:59:28)
    at OpenAIChatLanguageModel.getArgs (file:///Users/andrew/Documents/poka/repos/vercel-repro/node_modules/@ai-sdk/openai/src/chat/openai-chat-language-model.ts:111:53)
    at async OpenAIChatLanguageModel.doGenerate (file:///Users/andrew/Documents/poka/repos/vercel-repro/node_modules/@ai-sdk/openai/src/chat/openai-chat-language-model.ts:314:38)
    at async fn (file:///Users/andrew/Documents/poka/repos/vercel-repro/node_modules/ai/src/generate-text/generate-text.ts:382:32)
    at async file:///Users/andrew/Documents/poka/repos/vercel-repro/node_modules/ai/src/telemetry/record-span.ts:18:22
    at async _retryWithExponentialBackoff (file:///Users/andrew/Documents/poka/repos/vercel-repro/node_modules/ai/src/util/retry-with-exponential-backoff.ts:96:12) {
  cause: undefined,
  functionality: 'file part media type text/plain',
  [Symbol(vercel.ai.error)]: true,
  [Symbol(vercel.ai.error.AI_UnsupportedFunctionalityError)]: true
}
Error details: {
  "name": "AI_UnsupportedFunctionalityError",
  "functionality": "file part media type text/plain"
}

For the PDF

[[email protected]] injecting env (2) from .env -- tip: ๐Ÿ“ก version env with Radar: https://dotenvx.com/radar
(node:72725) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///Users/andrew/Documents/poka/repos/vercel-repro/index.ts is not specified and it doesn't parse as CommonJS.
Reparsing as ES module because module syntax was detected. This incurs a performance overhead.
To eliminate this warning, add "type": "module" to /Users/andrew/Documents/poka/repos/vercel-repro/package.json.
(Use `node --trace-warnings ...` to show where the warning was created)
Error occurred: APICallError [AI_APICallError]: Invalid Value: 'file'. This model does not support file content types.
    at file:///Users/andrew/Documents/poka/repos/vercel-repro/node_modules/@ai-sdk/provider-utils/src/response-handler.ts:56:16
    at processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async postToApi (file:///Users/andrew/Documents/poka/repos/vercel-repro/node_modules/@ai-sdk/provider-utils/src/post-to-api.ts:112:28)
    at async OpenAIChatLanguageModel.doGenerate (file:///Users/andrew/Documents/poka/repos/vercel-repro/node_modules/@ai-sdk/openai/src/chat/openai-chat-language-model.ts:320:9)
    at async fn (file:///Users/andrew/Documents/poka/repos/vercel-repro/node_modules/ai/src/generate-text/generate-text.ts:382:32)
    at async file:///Users/andrew/Documents/poka/repos/vercel-repro/node_modules/ai/src/telemetry/record-span.ts:18:22
    at async _retryWithExponentialBackoff (file:///Users/andrew/Documents/poka/repos/vercel-repro/node_modules/ai/src/util/retry-with-exponential-backoff.ts:96:12)
    at async fn (file:///Users/andrew/Documents/poka/repos/vercel-repro/node_modules/ai/src/generate-text/generate-text.ts:338:34)
    at async file:///Users/andrew/Documents/poka/repos/vercel-repro/node_modules/ai/src/telemetry/record-span.ts:18:22
    at async generateText (file:///Users/andrew/Documents/poka/repos/vercel-repro/node_modules/ai/src/generate-text/generate-text.ts:274:12) {
  cause: undefined,
  url: 'https://poka-open-ai-resource.openai.azure.com/openai/v1/chat/completions?api-version=preview',
  requestBodyValues: {
....

@arbass22 to get it work with PDF, you need to add azure.responses('gpt-4.1')

rahulbhadja avatar Oct 07 '25 16:10 rahulbhadja

I investigated this issue and tested with Azure/OpenAI API. The error occurs because OpenAI/Azure responses API only supports PDF files (not text/plain). openai file upload

According to Azure's documentation:

The SDK's error is correct.

Should we update the documentation to clarify which file types are compatible with which OpenAI/ Azure APIs?

@gr2m thoughts?

Hey, thanks for looking into this Rahul, but the issue is not related to azure or open ai model functionality.

In V4 you could add text/plain type files via experimental_attachments in useChat and Azure Open AI and Open AI models would accept and respond based on the content.

In V5, both providers now error if text/plain attachments are added.

I built a lot of functionality in V4 regarding attachments, where I would accept many different file types as attachments and this worked by first extracting the attachment content as plain text so that the model would accept it. This is now not working in V5 due to the error being thrown, even though the providers and models haven't changed.

matt-abstractai avatar Oct 07 '25 16:10 matt-abstractai

@matt-abstractai Thanks for clarifying! After investigating the v4 vs v5 behavior, here's what changed:

Why It Worked in v4

In v4, when you used experimental_attachments with text files, the SDK would automatically handle the conversion. However, the OpenAI/Azure APIs never actually supported text/plain as file attachments in the API spec.

What Changed in v5

V5 now strictly enforces the actual API limitations:

  • OpenAI Chat/Responses API only accepts: image/*, application/pdf, audio/*
  • Azure OpenAI follows the same limitations

The SDK now throws an error upfront for unsupported file types like text/plain.

The Solution

For text files, read the content and send as a text part:

import fs from 'fs';

// v4 approach (no longer works)
{
  type: 'file',
  data: fs.readFileSync('./document.txt'),
  mediaType: 'text/plain',
}

// v5 approach (correct way)
{
  type: 'text',
  text: fs.readFileSync('./document.txt', 'utf-8'),
}

correct me if I'm wrong @gr2m @lgrammel

rahulbhadja avatar Oct 07 '25 18:10 rahulbhadja