vercel/ai · error · APICallError
${response.error.message}
Error message
${response.error.message} What it means
After calling the Hugging Face Responses API in doGenerate, if the response body contains an error object, the model throws APICallError with the API's error message, a fabricated 400 status code, and the raw response body attached. This means the remote API rejected or failed the request; the SDK surfaces the upstream error text verbatim.
Source
Thrown at packages/huggingface/src/responses/huggingface-responses-language-model.ts:206
const {
value: response,
responseHeaders,
rawValue: rawResponse,
} = await postJsonToApi({
url,
headers: combineHeaders(this.config.headers?.(), options.headers),
body,
failedResponseHandler: huggingfaceFailedResponseHandler,
successfulResponseHandler: createJsonResponseHandler(
huggingfaceResponsesResponseSchema,
),
abortSignal: options.abortSignal,
fetch: this.config.fetch,
});
if (response.error) {
throw new APICallError({
message: response.error.message,
url,
requestBodyValues: body,
statusCode: 400,
responseHeaders,
responseBody: rawResponse as string,
isRetryable: false,
});
}
const content: Array<LanguageModelV4Content> = [];
// Process output array
for (const part of response.output) {
switch (part.type) {
case 'message': {
for (const contentPart of part.content) {
content.push({View on GitHub (pinned to 69428b1f8b)
Solutions
- Read the error message/responseBody in the thrown APICallError (and its cause/headers) to see the exact upstream failure.
- Verify the model ID exists and your HF token has access to it (check status/quota on huggingface.co).
- Fix the request payload per the message (e.g. unsupported parameters, oversized input) and retry.
Example fix
// before
const result = await generateText({ model: huggingface.responses('nonexistent/model'), prompt });
// after
const result = await generateText({ model: huggingface.responses('meta-llama/Llama-3.1-8B-Instruct'), prompt }); Defensive patterns
Strategy: retry
Validate before calling
if (!modelId || !modelId.includes('/')) {
throw new Error(`Invalid Hugging Face model id: '${modelId}'. Use 'namespace/model' format.`);
}
if (!process.env.HF_TOKEN && !apiKey) {
console.warn('No Hugging Face token configured; API calls may fail.');
} Type guard
import { APICallError } from '@ai-sdk/provider';
function isHfApiError(e: unknown): e is APICallError {
return APICallError.isInstance(e) && typeof e.responseBody === 'string' && e.responseBody.includes('error');
} Try / catch
import { APICallError } from '@ai-sdk/provider';
try {
return await generateText({ model, prompt });
} catch (e) {
if (APICallError.isInstance(e) && e.statusCode === 400) {
console.error('Hugging Face API error:', e.message, e.responseBody);
// inspect responseBody; do not blindly retry non-retryable 400s
}
throw e;
} Prevention
- Validate model IDs against the Hugging Face model hub before deploying.
- Ensure HF token is set and has quota/access to the target model (including gated models).
- Log responseBody from APICallError to catch upstream message changes early.
When it happens
Trigger: Any generateText/streamText call where the Hugging Face Responses API returns a JSON body with an error field — e.g. invalid model ID, malformed input, exceeded quota, or content policy rejection.
Common situations: Wrong or deprecated model ID; missing/invalid HF token causing auth errors reported in the body; prompt payload violating API constraints; Hugging Face service-side errors during outages.
Related errors
- Video generation timed out after ${timeoutMs}ms.
- The response body is empty.
- Incomplete Amazon Bedrock event-stream frame: ${buffer.lengt
- Failed to fetch the response.
- The response body is empty.
AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30).
Data as JSON: /api/errors/1fad8c49a6c40cee.
Report an issue: GitHub.