{"record":{"id":"dc77372be0c9e577","repo":"CopilotKit/CopilotKit","slug":"openai","errorCode":null,"errorMessage":"OpenAI","messagePattern":"OpenAI","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/runtime/src/v1-deprecated/service-adapters/openai/openai-adapter.ts","lineNumber":336,"sourceCode":"            } else if (mode === \"function\" && toolCall?.function?.arguments) {\n              eventStream$.sendActionExecutionArgs({\n                actionExecutionId: currentToolCallId,\n                args: toolCall.function.arguments,\n              });\n            }\n          }\n\n          // send the end events\n          if (mode === \"message\") {\n            eventStream$.sendTextMessageEnd({ messageId: currentMessageId });\n          } else if (mode === \"function\") {\n            eventStream$.sendActionExecutionEnd({\n              actionExecutionId: currentToolCallId,\n            });\n          }\n        } catch (error) {\n          console.error(\"[OpenAI] Error during API call:\", error);\n          throw convertServiceAdapterError(error, \"OpenAI\");\n        }\n\n        eventStream$.complete();\n      });\n    } catch (error) {\n      console.error(\"[OpenAI] Error during API call:\", error);\n      throw convertServiceAdapterError(error, \"OpenAI\");\n    }\n\n    return {\n      threadId,\n    };\n  }\n}\n","sourceCodeStart":318,"sourceCodeEnd":351,"githubUrl":"https://github.com/CopilotKit/CopilotKit/blob/68fbe97d87420bd84e8196965c71bd6e394a3f7a/packages/runtime/src/v1-deprecated/service-adapters/openai/openai-adapter.ts#L318-L351","documentation":"Thrown by the v1-deprecated OpenAI service adapter when the OpenAI API call fails during stream processing. The adapter logs `[OpenAI] Error during API call:` and wraps the failure via `convertServiceAdapterError(error, \"OpenAI\")`, so the thrown error names OpenAI but the cause is the underlying SDK/API error.","triggerScenarios":"Running an agent through OpenAIAdapter where the stream rejects: invalid OPENAI_API_KEY, unknown model, quota exhausted, invalid parameters, or network failure while iterating streamed chunks inside the eventSource callback.","commonSituations":"Missing/expired OPENAI_API_KEY or exhausted billing quota; using a model the org doesn't have access to (e.g. o1/gpt-4o variants under wrong org); passing unsupported forwarded parameters; corporate proxy blocking api.openai.com; SDK major-version mismatch with @copilotkit/runtime v1 adapters.","solutions":["Read the console.error line and error.cause for OpenAI's real status/message","Verify OPENAI_API_KEY, org/project settings, and billing quota","Confirm the model id is correct and available to your org","Remove/adjust unsupported forwarded parameters (e.g. temperature with reasoning models)","Retry transient 429/5xx with exponential backoff"],"exampleFix":"// before\nnew OpenAIAdapter({ model: \"gpt-4-turbo-preview\" }) // deprecated id\n\n// after\nnew OpenAIAdapter({ model: \"gpt-4o\" })","handlingStrategy":"try-catch","validationCode":"if (!process.env.OPENAI_API_KEY) throw new Error('OPENAI_API_KEY is not set');","typeGuard":"function isOpenAIAdapterError(e: unknown): boolean {\n  return e instanceof Error && /OpenAI/.test(e.message);\n}","tryCatchPattern":"try {\n  await agent.run(input);\n} catch (e) {\n  const cause = (e as any).cause ?? e;\n  if (/401|quota|billing/i.test(String(cause))) throw new Error('Check OpenAI key/billing');\n  if (/429/i.test(String(cause))) { await backoff(); return retry(); }\n  throw e;\n}","preventionTips":["Monitor OpenAI billing/quota before it hard-fails requests","Only forward parameters the target model supports","Inspect the logged `[OpenAI] Error during API call:` line for the true cause"],"tags":["openai","service-adapter","runtime","api-error","streaming"],"backgroundTag":"llm-provider-api-error","analyzedSha":"68fbe97d87420bd84e8196965c71bd6e394a3f7a","analyzedAt":"2026-08-27T04:03:26.537Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}