{"record":{"id":"5c8d04a79000d9e7","repo":"vercel/ai","slug":"file-part-media-type-block-mediatype-as-inline","errorCode":null,"errorMessage":"'file part media type ${block.mediaType} as inline data (xAI Responses requires a URL or a Files API reference for non-image files)' functionality not supported.","messagePattern":"'file part media type (.+?) as inline data \\(xAI Responses requires a URL or a Files API reference for non-image files\\)' functionality not supported\\.","errorType":"exception","errorClass":"UnsupportedFunctionalityError","httpStatus":null,"severity":"error","filePath":"packages/xai/src/responses/convert-to-xai-responses-input.ts","lineNumber":101,"sourceCode":"                    contentParts.push({\n                      type: 'input_image',\n                      image_url: imageUrl,\n                      ...(filePartOptions?.imageDetail != null && {\n                        detail: filePartOptions.imageDetail,\n                      }),\n                    });\n                  } else if (block.data.type === 'url') {\n                    // xAI's Responses API accepts non-image documents (PDF, text, CSV, etc.)\n                    // via `{ type: 'input_file', file_url }`. See\n                    // https://docs.x.ai/docs/guides/chat-with-files. Inline bytes for\n                    // non-image files are not supported by xAI; callers must upload via\n                    // the Files API and pass a provider reference (file_id) instead.\n                    contentParts.push({\n                      type: 'input_file',\n                      file_url: block.data.url.toString(),\n                    });\n                  } else {\n                    throw new UnsupportedFunctionalityError({\n                      functionality: `file part media type ${block.mediaType} as inline data (xAI Responses requires a URL or a Files API reference for non-image files)`,\n                    });\n                  }\n                  break;\n                }\n              }\n              break;\n            }\n\n            default: {\n              const _exhaustiveCheck: never = block;\n              inputWarnings.push({\n                type: 'other',\n                message:\n                  'xAI Responses API does not support this content type in user messages',\n              });\n            }\n          }","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/xai/src/responses/convert-to-xai-responses-input.ts#L83-L119","documentation":"For Responses API input, xAI only accepts non-image files via URL or a Files API file_id reference. Inline binary data (base64 'data') for non-image media types has no wire representation, so the converter throws UnsupportedFunctionalityError naming the media type.","triggerScenarios":"Passing a file part with data type 'data' (inline base64/binary) and a non-image mediaType (e.g. application/pdf, audio/*) to an xai responses model; image data parts are allowed, everything else inline is not.","commonSituations":"Embedding a PDF as base64 in the prompt; reusing prompts written for OpenAI/Anthropic that accept inline document data; generating files at runtime and attaching them inline.","solutions":["Upload the file to xAI's Files API and reference it via providerOptions/data reference (file_id)","Host the file at a URL and pass a file part with data: { type: 'url', url }","Convert the content to text parts if it can be represented as text"],"exampleFix":"// before\n{ type: 'file', mediaType: 'application/pdf', data: { type: 'data', data: base64Pdf } }\n// after (upload first, then reference)\n{ type: 'file', mediaType: 'application/pdf', data: { type: 'reference', reference: new ProviderReference({ fileId }) } }","handlingStrategy":"validation","validationCode":"for (const m of prompt) for (const p of m.content) {\n  if (p.type === 'file' && p.data.type === 'data' && !p.mediaType.startsWith('image/')) {\n    throw new Error('inline non-image file data unsupported by xai responses; upload to Files API first');\n  }\n}","typeGuard":"function isInlineNonImageFile(p: any): boolean {\n  return p?.type === 'file' && p?.data?.type === 'data' && !String(p?.mediaType ?? '').startsWith('image/');\n}","tryCatchPattern":"try {\n  await streamText({ model, prompt });\n} catch (e) {\n  if ((e as any).name === 'AI_UnsupportedFunctionalityError' && (e as Error).message.includes('as inline data')) {\n    // upload file to xAI Files API and rebuild prompt with a reference\n  }\n}","preventionTips":["Upload non-image documents to the xAI Files API up front","Use url-type file parts for hosted documents","Keep image data inline only (images are the supported inline case)"],"tags":["xai","unsupported-functionality","file-parts","inline-data"],"backgroundTag":"unsupported-functionality","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}