{"record":{"id":"c412e956a3e3e5bf","repo":"DayuanJiang/next-ai-draw-io","slug":"modelscope-api-error-response-status-error","errorCode":null,"errorMessage":"ModelScope API error (${response.status}): ${errorText}","messagePattern":"ModelScope API error \\((.+?)\\): (.+?)","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"app/api/validate-model/route.ts","lineNumber":311,"sourceCode":"                            headers: {\n                                \"Content-Type\": \"application/json\",\n                                Authorization: `Bearer ${apiKey}`,\n                            },\n                            body: JSON.stringify({\n                                model: modelId,\n                                messages: [\n                                    { role: \"user\", content: \"Say 'OK'\" },\n                                ],\n                                max_tokens: 20,\n                                stream: true,\n                                enable_thinking: false,\n                            }),\n                        },\n                    )\n\n                    if (!response.ok) {\n                        const errorText = await response.text()\n                        throw new Error(\n                            `ModelScope API error (${response.status}): ${errorText}`,\n                        )\n                    }\n\n                    const contentType =\n                        response.headers.get(\"content-type\") || \"\"\n                    const isValidStreamingResponse =\n                        response.status === 200 &&\n                        (contentType.includes(\"text/event-stream\") ||\n                            contentType.includes(\"application/json\"))\n\n                    if (!isValidStreamingResponse) {\n                        throw new Error(\n                            `Unexpected response format: ${contentType}`,\n                        )\n                    }\n\n                    const responseTime = Date.now() - startTime","sourceCodeStart":293,"sourceCodeEnd":329,"githubUrl":"https://github.com/DayuanJiang/next-ai-draw-io/blob/155ef4f7acd29c9d46fb6fc35c92e6e6955a6ce1/app/api/validate-model/route.ts#L293-L329","documentation":"ModelScope validation route proxies a request to the ModelScope API and throws when the upstream responds with a non-OK HTTP status, embedding the status code and raw error text.","triggerScenarios":"Calling POST /api/validate-model against a ModelScope endpoint with an invalid/expired API key (401), nonexistent model (404), or malformed request — the upstream error body is surfaced verbatim.","commonSituations":"Typo in the model ID, ModelScope API token expired, ModelScope changed its endpoint/response contract, or region-specific API restrictions.","solutions":["Check errorText in the message to identify the upstream cause (auth vs model vs quota)","Verify the ModelScope API key and model name are correct and active","Confirm the ModelScope inference endpoint URL matches the current ModelScope docs","Retry after correcting credentials/model; check ModelScope status page for outages"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const r = await fetch('/api/validate-model', { method: 'POST', body })\n} catch (e) {\n  const m = (e as Error).message\n  if (m.includes('401')) promptReenterApiKey()\n  else if (m.includes('404')) markModelInvalid()\n  else showUpstreamError(m)\n}","preventionTips":["Validate ModelScope token and model ID before calling","Surface errorText from the message for actionable user feedback","Rate-limit retries to avoid quota exhaustion"],"tags":["modelscope","upstream","http","validation"],"backgroundTag":"upstream-api-error","analyzedSha":"155ef4f7acd29c9d46fb6fc35c92e6e6955a6ce1","analyzedAt":"2026-08-27T11:40:38.297Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}