{"record":{"id":"1fad8c49a6c40cee","repo":"vercel/ai","slug":"response-error-message","errorCode":null,"errorMessage":"${response.error.message}","messagePattern":"\\$\\{response\\.error\\.message\\}","errorType":"http","errorClass":"APICallError","httpStatus":400,"severity":"error","filePath":"packages/huggingface/src/responses/huggingface-responses-language-model.ts","lineNumber":206,"sourceCode":"\n    const {\n      value: response,\n      responseHeaders,\n      rawValue: rawResponse,\n    } = await postJsonToApi({\n      url,\n      headers: combineHeaders(this.config.headers?.(), options.headers),\n      body,\n      failedResponseHandler: huggingfaceFailedResponseHandler,\n      successfulResponseHandler: createJsonResponseHandler(\n        huggingfaceResponsesResponseSchema,\n      ),\n      abortSignal: options.abortSignal,\n      fetch: this.config.fetch,\n    });\n\n    if (response.error) {\n      throw new APICallError({\n        message: response.error.message,\n        url,\n        requestBodyValues: body,\n        statusCode: 400,\n        responseHeaders,\n        responseBody: rawResponse as string,\n        isRetryable: false,\n      });\n    }\n\n    const content: Array<LanguageModelV4Content> = [];\n\n    // Process output array\n    for (const part of response.output) {\n      switch (part.type) {\n        case 'message': {\n          for (const contentPart of part.content) {\n            content.push({","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/huggingface/src/responses/huggingface-responses-language-model.ts#L188-L224","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nconst result = await generateText({ model: huggingface.responses('nonexistent/model'), prompt });\n// after\nconst result = await generateText({ model: huggingface.responses('meta-llama/Llama-3.1-8B-Instruct'), prompt });","handlingStrategy":"retry","validationCode":"if (!modelId || !modelId.includes('/')) {\n  throw new Error(`Invalid Hugging Face model id: '${modelId}'. Use 'namespace/model' format.`);\n}\nif (!process.env.HF_TOKEN && !apiKey) {\n  console.warn('No Hugging Face token configured; API calls may fail.');\n}","typeGuard":"import { APICallError } from '@ai-sdk/provider';\nfunction isHfApiError(e: unknown): e is APICallError {\n  return APICallError.isInstance(e) && typeof e.responseBody === 'string' && e.responseBody.includes('error');\n}","tryCatchPattern":"import { APICallError } from '@ai-sdk/provider';\ntry {\n  return await generateText({ model, prompt });\n} catch (e) {\n  if (APICallError.isInstance(e) && e.statusCode === 400) {\n    console.error('Hugging Face API error:', e.message, e.responseBody);\n    // inspect responseBody; do not blindly retry non-retryable 400s\n  }\n  throw e;\n}","preventionTips":["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."],"tags":["api-call-error","network","provider-api"],"backgroundTag":"api-error-response","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}