{"record":{"id":"0eebf72354b5a530","repo":"vercel/ai","slug":"response-error","errorCode":null,"errorMessage":"${response.error}","messagePattern":"\\$\\{response\\.error\\}","errorType":"exception","errorClass":"APICallError","httpStatus":200,"severity":"error","filePath":"packages/xai/src/xai-chat-language-model.ts","lineNumber":277,"sourceCode":"\n    const {\n      responseHeaders,\n      value: response,\n      rawValue: rawResponse,\n    } = await postJsonToApi({\n      url,\n      headers: combineHeaders(this.config.headers?.(), options.headers),\n      body,\n      failedResponseHandler: xaiFailedResponseHandler,\n      successfulResponseHandler: createJsonResponseHandler(\n        xaiChatResponseSchema,\n      ),\n      abortSignal: options.abortSignal,\n      fetch: this.config.fetch,\n    });\n\n    if (response.error != null) {\n      throw new APICallError({\n        message: response.error,\n        url,\n        requestBodyValues: body,\n        statusCode: 200,\n        responseHeaders,\n        responseBody: JSON.stringify(rawResponse),\n        isRetryable: response.code === 'The service is currently unavailable',\n      });\n    }\n\n    const choice = response.choices![0];\n    const content: Array<LanguageModelV4Content> = [];\n\n    // extract text content\n    if (choice.message.content != null && choice.message.content.length > 0) {\n      let text = choice.message.content;\n\n      // skip if this content duplicates the last assistant message","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/xai/src/xai-chat-language-model.ts#L259-L295","documentation":"When the xAI chat completions endpoint returns HTTP 200 but the JSON body contains an error field, doGenerate surfaces it as an APICallError with statusCode 200. xAI occasionally reports errors inside a 200 response, so the SDK explicitly checks response.error after parsing.","triggerScenarios":"A successful-looking 200 response from api.x.ai/v1/chat/completions whose body is { error: ... } — e.g. moderation blocks, content filtered at generation time, or partial gateway failures passing through 200.","commonSituations":"Prompt content triggering xAI safety errors returned in-band; proxy/gateway layers that convert failures into 200-wrapped errors; streaming-unaware intermediary returning error JSON.","solutions":["Read the APICallError message (the raw response.error) to identify the xAI-side cause and adjust the prompt/parameters","Inspect responseBody in the error for the full payload; remove or rephrase content if it is a policy error","Check whether a proxy/gateway is rewriting error statuses to 200 and fix it so normal error handling applies"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"import { APICallError } from 'ai';\ntry {\n  const { text } = await generateText({ model, prompt });\n} catch (e) {\n  if (APICallError.isInstance(e) && e.statusCode === 200) {\n    console.error('xAI in-band error:', e.message, e.responseBody);\n  }\n}","preventionTips":["Always use APICallError.isInstance rather than checking HTTP status alone","Log responseBody for in-band (200) errors to see xAI's detail","Screen prompts for policy-sensitive content before sending"],"tags":["xai","api-call-error","http-200","chat"],"backgroundTag":"api-error-in-200-response","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}