CopilotKit/CopilotKit · error
OpenAI
Error message
OpenAI
What it means
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.
Source
Thrown at packages/runtime/src/v1-deprecated/service-adapters/openai/openai-adapter.ts:336
} else if (mode === "function" && toolCall?.function?.arguments) {
eventStream$.sendActionExecutionArgs({
actionExecutionId: currentToolCallId,
args: toolCall.function.arguments,
});
}
}
// send the end events
if (mode === "message") {
eventStream$.sendTextMessageEnd({ messageId: currentMessageId });
} else if (mode === "function") {
eventStream$.sendActionExecutionEnd({
actionExecutionId: currentToolCallId,
});
}
} catch (error) {
console.error("[OpenAI] Error during API call:", error);
throw convertServiceAdapterError(error, "OpenAI");
}
eventStream$.complete();
});
} catch (error) {
console.error("[OpenAI] Error during API call:", error);
throw convertServiceAdapterError(error, "OpenAI");
}
return {
threadId,
};
}
}
View on GitHub (pinned to 68fbe97d87)
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
Example fix
// before
new OpenAIAdapter({ model: "gpt-4-turbo-preview" }) // deprecated id
// after
new OpenAIAdapter({ model: "gpt-4o" }) Defensive patterns
Strategy: try-catch
Validate before calling
if (!process.env.OPENAI_API_KEY) throw new Error('OPENAI_API_KEY is not set'); Type guard
function isOpenAIAdapterError(e: unknown): boolean {
return e instanceof Error && /OpenAI/.test(e.message);
} Try / catch
try {
await agent.run(input);
} catch (e) {
const cause = (e as any).cause ?? e;
if (/401|quota|billing/i.test(String(cause))) throw new Error('Check OpenAI key/billing');
if (/429/i.test(String(cause))) { await backoff(); return retry(); }
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Anthropic
- Groq
- No default agent provided. Please provide a default agent in
- channel_memory_unavailable
- AI SDK tool-approval-request is missing toolCallId
AI-assisted analysis of CopilotKit/CopilotKit@68fbe97d87 (2026-08-27).
Data as JSON: /api/errors/dc77372be0c9e577.
Report an issue: GitHub.