earendil-works/pi · error
No API key for provider: ${provider}
Error message
No API key for provider: ${provider} What it means
Error "No API key for provider: ${provider}" thrown in earendil-works/pi.
Source
Thrown at packages/ai/src/api/openai-completions.ts:79
/**
* Check if conversation messages contain tool calls or tool results.
* This is needed because Anthropic (via proxy) requires the tools param
* to be present when messages include tool_calls or tool role messages.
*/
function hasHeader(headers: ProviderHeaders | undefined, name: string): boolean {
if (!headers) return false;
const expected = name.toLowerCase();
for (const [key, value] of Object.entries(headers)) {
if (key.toLowerCase() === expected && value !== null && value.trim().length > 0) return true;
}
return false;
}
function getClientApiKey(provider: string, apiKey: string | undefined, headers: ProviderHeaders | undefined): string {
if (apiKey) return apiKey;
if (hasHeader(headers, "authorization") || hasHeader(headers, "cf-aig-authorization")) return "unused";
throw new Error(`No API key for provider: ${provider}`);
}
function hasToolHistory(messages: Message[]): boolean {
for (const msg of messages) {
if (msg.role === "toolResult") {
return true;
}
if (msg.role === "assistant") {
if (msg.content.some((block) => block.type === "toolCall")) {
return true;
}
}
}
return false;
}
function getDeferredToolNames(messages: Message[]): Set<string> {
const names = new Set<string>();View on GitHub (pinned to 4af9d21d3b)
Solutions
- Set the provider API key environment variable, or pass apiKey explicitly.
When it happens
Trigger: Thrown at packages/ai/src/api/openai-completions.ts:79 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of earendil-works/pi@4af9d21d3b (2026-08-24).
Data as JSON: /api/errors/5b205115bca76fcd.
Report an issue: GitHub.