{"record":{"id":"4c9a47724659e7fe","repo":"ruvnet/ruflo","slug":"openai-embedding-failed-message","errorCode":null,"errorMessage":"OpenAI embedding failed: ${message}","messagePattern":"OpenAI embedding failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/embeddings/src/embedding-service.ts","lineNumber":254,"sourceCode":"\n      // Cache result\n      this.cache.set(text, embedding);\n\n      const latencyMs = performance.now() - startTime;\n      this.emitEvent({ type: 'embed_complete', text, latencyMs });\n\n      return {\n        embedding,\n        latencyMs,\n        usage: {\n          promptTokens: response.usage?.prompt_tokens ?? 0,\n          totalTokens: response.usage?.total_tokens ?? 0,\n        },\n      };\n    } catch (error) {\n      const message = error instanceof Error ? error.message : 'Unknown error';\n      this.emitEvent({ type: 'embed_error', text, error: message });\n      throw new Error(`OpenAI embedding failed: ${message}`);\n    }\n  }\n\n  async embedBatch(texts: string[]): Promise<BatchEmbeddingResult> {\n    this.emitEvent({ type: 'batch_start', count: texts.length });\n    const startTime = performance.now();\n\n    // Check cache for each text\n    const cached: Array<{ index: number; embedding: Float32Array }> = [];\n    const uncached: Array<{ index: number; text: string }> = [];\n\n    texts.forEach((text, index) => {\n      const cachedEmbedding = this.cache.get(text);\n      if (cachedEmbedding) {\n        cached.push({ index, embedding: cachedEmbedding });\n        this.emitEvent({ type: 'cache_hit', text });\n      } else {\n        uncached.push({ index, text });","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/embeddings/src/embedding-service.ts#L236-L272","documentation":"OpenAIEmbeddingService.embed() wraps every failure of the underlying callOpenAI() request in 'OpenAI embedding failed: <cause>'. The embedded cause text identifies the real problem: an HTTP error (auth, quota, model), a network/timeout failure (default 30s), or a malformed response. An embed_error event is emitted to registered listeners before the throw, so the failing text is observable.","triggerScenarios":"embed(text) with a missing/invalid config.apiKey (the constructor reads config.apiKey directly — 401 from the API), a typo'd config.model (default 'text-embedding-3-small'), input exceeding the model token limit, a timeout beyond config.timeout (30000ms default), or a config.baseURL pointing at a wrong path; callOpenAI retries maxRetries (default 3) times, then embed() wraps the final error.","commonSituations":"Empty or placeholder apiKey in config; Azure/OpenRouter proxies needing a different baseURL; whole documents fed as one embed() call; retired or misspelled model names.","solutions":["Read the wrapped cause and map it: 401 → fix apiKey; model errors → fix config.model; timeout → raise config.timeout or shrink input","Chunk long text before embedding (e.g. split to a few thousand tokens per call)","For flaky networks, raise config.maxRetries or add call-site retry with backoff around embed()/embedBatch()"],"exampleFix":"// before\nconst svc = new OpenAIEmbeddingService({ apiKey: '' });\nawait svc.embed('hello'); // OpenAI embedding failed: OpenAI API error: 401 - ...\n\n// after\nconst svc = new OpenAIEmbeddingService({ apiKey: process.env.OPENAI_API_KEY! });\nawait svc.embed('hello');","handlingStrategy":"try-catch","validationCode":"function hasEmbeddingConfig(cfg: { apiKey?: string; model?: string; baseURL?: string }): boolean {\n  return typeof cfg.apiKey === 'string' && cfg.apiKey.length > 20\n    && (cfg.model ?? 'text-embedding-3-small').length > 0;\n}\nif (!hasEmbeddingConfig(config)) throw new Error('embedding config incomplete');\nconst svc = new OpenAIEmbeddingService(config);","typeGuard":null,"tryCatchPattern":"try {\n  const { embedding } = await svc.embed(text);\n} catch (e) {\n  const msg = e instanceof Error ? e.message : String(e);\n  if (msg.startsWith('OpenAI embedding failed:')) {\n    const cause = msg.slice('OpenAI embedding failed:'.length).trim();\n    if (cause.includes('401')) throw new Error('bad API key');\n    if (cause.includes('429')) await sleep(backoffMs), retry();\n    if (cause.includes('timeout') || cause.includes('ETIMEDOUT')) chunk smaller;\n  } else throw e;\n}","preventionTips":["Validate apiKey/model/baseURL before constructing the service","Chunk long inputs; subscribe an event listener for embed_error to log failing texts"],"tags":["openai","embeddings","api","network","llm"],"backgroundTag":"openai-api-error","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}