@bluboks/langchain-codex-oauth-js
v0.1.0
Published
Unofficial LangChain JS chat model for OpenAI Codex OAuth in Node.js and TypeScript
Maintainers
Readme
@bluboks/langchain-codex-oauth-js
Community-maintained LangChain JS chat model for OpenAI Codex OAuth in Node.js and TypeScript.
This package provides a LangChain BaseChatModel implementation for Node.js and TypeScript projects that want to authenticate with OpenAI Codex via OAuth, reuse stored tokens, list available models, and send chat requests through LangChain.
This is not an official OpenAI or LangChain package.
Features
- OAuth PKCE login flow with automatic browser launch or manual copy/paste login.
- Token persistence and refresh support for repeat usage.
- LangChain-compatible chat model with streaming support.
- Model catalog helpers for discovering available Codex models.
- Node.js-first defaults, including WSL-friendly browser launching.
Requirements
- Node.js 20 or newer.
- A project that already uses
@langchain/core.
Install
npm install @bluboks/langchain-codex-oauth-js @langchain/coreQuick Start
import { CodexOAuthChat } from "@bluboks/langchain-codex-oauth-js";
const llm = new CodexOAuthChat({
modelName: "gpt-5.4",
autoAuth: false,
});
const loginUrl = await llm.startLogin({ openBrowser: false });
console.log("Open this URL and approve access:", loginUrl);
await llm.completeLogin();
const message = await llm.invoke("Write one sentence about TypeScript.");
console.log(message.content);By default, tokens are stored at ~/.langchain_codex_oauth/token.json and reused on later runs.
Automatic Authentication
If you want the package to open the browser on demand when no valid token is available, leave autoAuth enabled.
import { CodexOAuthChat } from "@bluboks/langchain-codex-oauth-js";
const llm = new CodexOAuthChat({
modelName: "gpt-5.4",
});
const message = await llm.invoke("Summarize the benefits of strong typing.");
console.log(message.content);Manual Login Flow
Use manual login when you do not want the package to launch a browser automatically.
import { CodexOAuthChat } from "@bluboks/langchain-codex-oauth-js";
const llm = new CodexOAuthChat({ autoAuth: false });
const loginUrl = await llm.startLogin({ openBrowser: false });
console.log(loginUrl);
await llm.completeLogin();List Available Models
import { CodexOAuthChat } from "@bluboks/langchain-codex-oauth-js";
const llm = new CodexOAuthChat();
const models = await llm.listModels({ visibleOnly: true });
console.log(models.map((model) => model.slug));Common Configuration
You can configure the client either through constructor fields or environment variables.
| Purpose | Constructor field | Environment variable | Default |
| --- | --- | --- | --- |
| Model name | modelName | CODEX_MODEL | gpt-5.4 |
| Codex responses endpoint | apiUrl | CODEX_API_URL | https://chatgpt.com/backend-api/codex/responses |
| Codex models endpoint | modelsUrl | CODEX_MODELS_URL | Derived from apiUrl |
| Token file path | tokenPath | CODEX_TOKEN_PATH | ~/.langchain_codex_oauth/token.json |
| OAuth client id | clientId | OPENAI_OAUTH_CLIENT_ID | Built-in public default |
| OAuth authorize URL | authUrl | OPENAI_OAUTH_AUTHORIZE_URL | https://auth.openai.com/oauth/authorize |
| OAuth token URL | tokenUrl | OPENAI_OAUTH_TOKEN_URL | https://auth.openai.com/oauth/token |
| OAuth scopes | scopes | OPENAI_OAUTH_SCOPES | Built-in Codex scopes |
| Browser auto-open | openBrowser | - | true |
| Automatic login fallback | autoAuth | - | true |
Additional OAuth query parameters can be supplied with authorizeExtraParams, or through OPENAI_OAUTH_ORIGINATOR and OPENAI_OAUTH_ALLOWED_WORKSPACE_ID.
WSL Notes
- Browser auto-open is best effort and tries
wslview,explorer.exe,powershell.exe, andcmd.exebefore generic Linux launchers. - If browser integration is unreliable in your environment, prefer
startLogin({ openBrowser: false })and open the URL yourself.
Local Development
npm install
npm run build
npm test
npm run smoke -- --manualLicense
MIT
