{"record":{"id":"ce0cb5036e38ae10","repo":"mastra-ai/mastra","slug":"request-timeout","errorCode":"REQUEST_TIMEOUT","errorMessage":"REQUEST_TIMEOUT: Request timed out after ${options.timeoutMs}ms","messagePattern":"REQUEST_TIMEOUT: Request timed out after (.+?)ms","errorType":"error_code","errorClass":"ApiCliError","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/api/client.ts","lineNumber":46,"sourceCode":"    if (options.descriptor.method !== 'GET' && bodyInput) {\n      init.headers = { 'content-type': 'application/json', ...init.headers };\n      init.body = JSON.stringify(bodyInput);\n    }\n\n    const response = await fetch(url, init);\n    const body = await parseResponse(response);\n\n    if (!response.ok) {\n      throw new ApiCliError('HTTP_ERROR', `Request failed with status ${response.status}`, {\n        status: response.status,\n        body,\n      });\n    }\n\n    return body;\n  } catch (error) {\n    if (error instanceof Error && error.name === 'AbortError') {\n      throw new ApiCliError('REQUEST_TIMEOUT', `Request timed out after ${options.timeoutMs}ms`, {\n        timeoutMs: options.timeoutMs,\n      });\n    }\n    throw toApiCliError(error);\n  } finally {\n    clearTimeout(timeout);\n  }\n}\n\nexport function buildUrl(\n  baseUrl: string,\n  path: string,\n  pathParams: Record<string, string>,\n  input?: Record<string, unknown>,\n  apiPrefix?: string,\n): string {\n  const pathParamNames = new Set<string>();\n  const resolvedPath = path.replace(/:([A-Za-z0-9_]+)/g, (_, name: string) => {","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/cli/src/commands/api/client.ts#L28-L64","documentation":"requestApi wraps every fetch with an AbortController whose timer fires after options.timeoutMs. If the abort fires before the HTTP exchange completes, the fetch rejects with an AbortError, which requestApi converts into ApiCliError('REQUEST_TIMEOUT', ...). It exists so CLI callers get a consistent, typed error instead of a raw abort signal when the Mastra server is slow or unreachable in time.","triggerScenarios":"Calling requestApi (directly or via fetchSchemaManifest or executeDescriptor) where the fetch of baseUrl + descriptor path does not complete within options.timeoutMs — e.g. server hung, slow network, or a very small timeoutMs value.","commonSituations":"Pointing the CLI at a Mastra server that is overloaded, starting up, or behind a stalled proxy; setting --timeout / timeoutMs too low for heavy endpoints (large schema manifests, long agent generations); running against localhost while the dev server is paused in a debugger.","solutions":["Retry with a larger timeoutMs (check the reported value in the error details and raise it, e.g. 10000-60000ms).","Verify the Mastra server is running and reachable at the configured baseUrl (curl the endpoint manually) and check server logs for slowness.","If the endpoint is inherently slow, use a non-blocking health/schema check first, then call the slow endpoint with an adequate timeout.","For persistent slowness, investigate server-side: DB/storage latency, background tasks, or resource contention on the host."],"exampleFix":"// before\nawait requestApi({ baseUrl, headers, timeoutMs: 1000, descriptor, pathParams });\n// after\nawait requestApi({ baseUrl, headers, timeoutMs: 30000, descriptor, pathParams });","handlingStrategy":"retry","validationCode":"// Optionally pre-check reachability before the real call\nconst ctrl = new AbortController();\nconst t = setTimeout(() => ctrl.abort(), 2000);\ntry {\n  await fetch(new URL('/api', baseUrl), { signal: ctrl.signal });\n} finally {\n  clearTimeout(t);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await requestApi({ baseUrl, headers, timeoutMs, descriptor, pathParams });\n} catch (e) {\n  if (e instanceof ApiCliError && e.code === 'REQUEST_TIMEOUT') {\n    // retry with backoff and/or a larger timeoutMs\n  } else {\n    throw e;\n  }\n}","preventionTips":["Set timeoutMs generously for heavy endpoints (schema fetches, agent runs); 1-2s is rarely enough.","Implement retry with exponential backoff for idempotent GET commands.","Verify the server health endpoint before long-running calls.","Surface the timeoutMs from error details in your own error messages so users know what to raise."],"tags":["network","timeout","cli","http"],"backgroundTag":"request-timeout","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}