Skip to content

Commit 8cfcf4c

Browse files
committed
Make API key optional — fall back to local Codex CLI auth
1 parent 59ba3ff commit 8cfcf4c

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

codegen-llm/src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ program
8080
rawOpts.apiKey ||
8181
process.env.OPENAI_API_KEY ||
8282
process.env.CODEX_API_KEY ||
83-
"",
83+
undefined,
8484
verbose: rawOpts.verbose,
8585
};
8686

codegen-llm/src/codegen.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export async function runCodegen(opts: CodegenOptions): Promise<void> {
4141
// -----------------------------------------------------------------------
4242
// 3. Start Codex session
4343
// -----------------------------------------------------------------------
44-
const codex = new Codex({ apiKey: opts.apiKey });
44+
const codex = new Codex(opts.apiKey ? { apiKey: opts.apiKey } : {});
4545

4646
// The agent gets its own workspace as the working directory, with
4747
// additional read access to the server source (and existing client if
@@ -132,9 +132,12 @@ export async function runCodegen(opts: CodegenOptions): Promise<void> {
132132
// ---------------------------------------------------------------------------
133133

134134
function validatePrerequisites(opts: CodegenOptions): void {
135+
// API key is optional — if omitted the Codex CLI will use its locally
136+
// stored session (from `codex` → "Sign in with ChatGPT").
135137
if (!opts.apiKey) {
136-
throw new Error(
137-
"API key required. Set OPENAI_API_KEY / CODEX_API_KEY or use --api-key.",
138+
log(
139+
opts,
140+
"No API key provided; relying on local Codex CLI authentication.",
138141
);
139142
}
140143

codegen-llm/src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export interface CodegenOptions {
1515
effort: "low" | "medium" | "high" | "xhigh";
1616
/** Maximum number of generation + verification attempts */
1717
maxAttempts: number;
18-
/** OpenAI API key */
19-
apiKey: string;
18+
/** OpenAI API key (optional — if omitted, uses local Codex CLI auth) */
19+
apiKey?: string;
2020
/** Print verbose output */
2121
verbose: boolean;
2222
}

0 commit comments

Comments
 (0)