ruvnet/ruflo · error · AuthenticationError
AUTHENTICATION
AUTHENTICATION
Error message
OpenAI API key is required
What it means
OpenAIProvider.doInitialize() runs during provider.initialize(); if config.apiKey is falsy it throws AuthenticationError before any HTTP call. The key becomes the Authorization: Bearer header against https://api.openai.com/v1 (or config.apiUrl), and providerOptions.organization optionally sets the OpenAI-Organization header.
Source
Thrown at v3/@claude-flow/providers/src/openai-provider.ts:180
},
'o3-mini': {
promptCostPer1k: 0.0011,
completionCostPer1k: 0.0044,
currency: 'USD',
},
},
};
private baseUrl: string = 'https://api.openai.com/v1';
private headers: Record<string, string> = {};
constructor(options: BaseProviderOptions) {
super(options);
}
protected async doInitialize(): Promise<void> {
if (!this.config.apiKey) {
throw new AuthenticationError('OpenAI API key is required', 'openai');
}
this.baseUrl = this.config.apiUrl || 'https://api.openai.com/v1';
this.headers = {
Authorization: `Bearer ${this.config.apiKey}`,
'Content-Type': 'application/json',
};
if (this.config.providerOptions?.organization) {
this.headers['OpenAI-Organization'] = this.config.providerOptions.organization as string;
}
}
protected async doComplete(request: LLMRequest): Promise<LLMResponse> {
const openAIRequest = this.buildRequest(request);
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), this.config.timeout || 60000);View on GitHub (pinned to fa13ee4ad6)
Solutions
- Pass the key explicitly: config: { apiKey: process.env.OPENAI_API_KEY, model: 'gpt-4o' }
- Verify the env var in the actual runtime: printenv OPENAI_API_KEY (or docker exec ... printenv)
- Load .env before constructing the provider (import 'dotenv/config' or node --env-file=.env)
- Add a startup check that fails with a clear message when required keys are absent
Example fix
// before
// node app.js (no dotenv loaded)
const provider = new OpenAIProvider({
name: 'openai',
config: { model: 'gpt-4o' }, // apiKey undefined -> AuthenticationError at initialize()
});
// after
// node --env-file=.env app.js
const provider = new OpenAIProvider({
name: 'openai',
config: { apiKey: process.env.OPENAI_API_KEY!, model: 'gpt-4o' },
}); Defensive patterns
Strategy: validation
Validate before calling
const apiKey = process.env.OPENAI_API_KEY;
if (!apiKey) {
throw new Error('OPENAI_API_KEY is not set - cannot create openai provider');
}
const provider = new OpenAIProvider({ name: 'openai', config: { apiKey, model: 'gpt-4o' } }); Type guard
import { AuthenticationError } from './types.js';
function isAuthError(e: unknown): e is AuthenticationError {
return e instanceof AuthenticationError;
} Try / catch
try {
await provider.initialize();
} catch (e) {
if (e instanceof AuthenticationError) {
throw new Error(`openai credentials missing or invalid: ${e.message}`); // config bug - no retry
}
throw e;
} Prevention
- Load .env explicitly (node --env-file=.env or import 'dotenv/config') before building providers
- Assert required env vars in a startup validator that names the variable
- Mount Docker/Kubernetes secrets and verify with printenv inside the container
When it happens
Trigger: new OpenAIProvider({ name: 'openai', config: { model: 'gpt-4o' } }) with no apiKey, or apiKey: process.env.OPENAI_API_KEY when the variable is unset in that runtime.
Common situations: OPENAI_API_KEY missing in CI/CD or Docker (secret not mounted); .env file present but not loaded (missing --env-file / dotenv import); key named OPENAI_KEY instead of OPENAI_API_KEY.
Related errors
- AUTHENTICATION
- AUTHENTICATION
- Config manager is disabled
- Model is required for ${this.name} provider
- unknown game "${key}". Known: ${Object.keys(GAMES).join(', '
AI-assisted analysis of ruvnet/ruflo@fa13ee4ad6 (2026-08-18).
Data as JSON: /api/errors/4c5fb991191b966b.
Report an issue: GitHub.