Skip to content

Instantly share code, notes, and snippets.

@ben-vargas
Created February 11, 2026 22:46
Show Gist options
  • Select an option

  • Save ben-vargas/1ce34c877c077527bde1f75a270359ff to your computer and use it in GitHub Desktop.

Select an option

Save ben-vargas/1ce34c877c077527bde1f75a270359ff to your computer and use it in GitHub Desktop.
Codex OAuth Backend Example
#!/usr/bin/env node
// Minimal REST call to the Codex backend API using a local OAuth token.
import fs from "fs";
import os from "os";
import path from "path";
const authFile = process.env.CODEX_AUTH_FILE || path.join(os.homedir(), ".codex", "auth.json");
const auth = JSON.parse(fs.readFileSync(authFile, "utf8"));
const token = auth.access_token || auth.tokens?.access_token;
if (!token) throw new Error("auth file missing access_token");
const url = process.env.CODEX_URL || "https://chatgpt.com/backend-api/codex/responses";
const model = process.env.CODEX_MODEL || "gpt-5.3-codex";
const res = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${token}`,
},
body: JSON.stringify({
model,
instructions: "",
stream: true,
store: false,
reasoning: { effort: "xhigh" },
input: [
{
type: "message",
role: "user",
content: [{ type: "input_text", text: "Hello from the minimal example." }],
},
],
}),
});
if (!res.ok) {
console.error(`HTTP ${res.status}`);
console.error(await res.text());
process.exit(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment