{"record":{"id":"2e93eaded1a4e5ec","repo":"linshenkx/prompt-optimizer","slug":"cloudflare-model-search-failed-await-this-geter","errorCode":null,"errorMessage":"Cloudflare model search failed: ${await this.getErrorMessage(response)}","messagePattern":"Cloudflare model search failed: (.+?)","errorType":"exception","errorClass":"APIError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/llm/adapters/cloudflare-adapter.ts","lineNumber":75,"sourceCode":"        }\n      }\n    };\n  }\n\n  public async getModelsAsync(config: TextModelConfig): Promise<TextModel[]> {\n    const accountId = this.getAccountId(config);\n    const baseURL = this.resolveCloudflareManagementBaseURL(config.connectionConfig.baseURL, accountId);\n    const url = `${baseURL}/models/search?task=${encodeURIComponent('Text Generation')}&hide_experimental=true&per_page=100`;\n\n    const response = await fetch(url, {\n      method: 'GET',\n      headers: {\n        Authorization: `Bearer ${config.connectionConfig.apiKey || ''}`\n      }\n    });\n\n    if (!response.ok) {\n      throw new APIError(`Cloudflare model search failed: ${await this.getErrorMessage(response)}`);\n    }\n\n    const data = await response.json();\n    if (!data?.success || !Array.isArray(data?.result)) {\n      throw new APIError('Cloudflare model search returned an unexpected response format');\n    }\n\n    const models = data.result\n      .filter((model: CloudflareModelSearchResult) => {\n        return model?.task?.name === 'Text Generation' && typeof model?.name === 'string' && !!model.name.trim();\n      })\n      .map((model: CloudflareModelSearchResult) => this.mapDynamicModel(model));\n\n    return models.length > 0 ? models : this.getModels();\n  }\n\n  public getModels(): TextModel[] {\n    return CLOUDFLARE_STATIC_MODELS.map((definition) => {","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/llm/adapters/cloudflare-adapter.ts#L57-L93","documentation":"CloudflareAdapter.getModelsAsync calls Cloudflare's model search REST endpoint with a Bearer token; when the HTTP response is not ok it throws APIError with the status and body text extracted by getErrorMessage. This covers auth failures and bad requests against the Cloudflare AI Gateway/Workers AI catalog API.","triggerScenarios":"Calling getModelsAsync() with an invalid API token (401), wrong account ID producing 403/404, malformed query, or Cloudflare API incidents (5xx).","commonSituations":"Expired/revoked Cloudflare API token, token missing 'Workers AI / Model read' permissions, wrong accountId in connection config.","solutions":["Inspect the appended status/body: 401 → create a new API token with Workers AI permissions","Verify connectionConfig.apiKey is set and is the Cloudflare token (not an OpenAI key)","Check accountId matches the Cloudflare account (see getAccountId)","Check Cloudflare status page for ongoing incidents if 5xx"],"exampleFix":"// before\nconst models = await adapter.getModelsAsync()\n\n// after\ntry {\n  const models = await adapter.getModelsAsync()\n} catch (e: any) {\n  if (e instanceof APIError && e.message.includes('model search failed')) {\n    logAndNotify('Cloudflare model listing failed', e.message)\n  }\n  throw e\n}","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"function isCloudflareHttpError(e: unknown): boolean {\n  return e instanceof APIError && e.message.includes('Cloudflare model search failed')\n}","tryCatchPattern":"try { models = await adapter.getModelsAsync() }\ncatch (e) {\n  if (isCloudflareHttpError(e)) { notify(e.message); models = [] }\n  else throw e\n}","preventionTips":["Create API tokens with minimal Workers AI permissions and track expiry","Validate accountId+apiKey pair at config save time","Cache model lists to avoid frequent listing calls"],"tags":["cloudflare","workers-ai","http-status","api-token"],"backgroundTag":"llm-api-http-error","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}