langchain-codex-oauth
A LangChain and LangGraph adapter that bridged local ChatGPT OAuth, streaming responses, and tool calls into a familiar chat-model interface.
01
Overview
What this is
langchain-codex-oauth was a small compatibility layer for a narrow gap: use Codex-capable ChatGPT models through a local OAuth session while keeping LangChain and LangGraph code shaped around their standard chat-model interface.
The adapter handled more than a single request. It translated messages and tool schemas, supported synchronous and asynchronous invocation, streamed server-sent events into LangChain chunks, reconstructed tool calls, exposed usage metadata, and included a local PKCE authentication flow. It was packaged as version 1.0.0 and later deliberately marked legacy when the ecosystem gained better-supported paths.
Built for local, single-user experiments and agent workflows that already used LangChain or LangGraph but needed to call the Codex response surface without reworking the surrounding application.
The problem
The model endpoint and the framework disagreed on authentication, request shape, streaming events, and tool-call semantics. A thin wrapper that only returned text would work for a demo but fail in the agent workflows the integration existed to support.
What I built and owned
I designed and implemented the adapter, OAuth flow, response and streaming translation, tool-call handling, structured-output compatibility, test suite, examples, and package documentation. I also defined the local-only boundaries and later marked the project legacy instead of presenting an unstable consumer integration as a production dependency.
02
Detail
How it works
A protocol bridge, not just an HTTP wrapper
LangChain expects a chat model to accept its messages and tools, emit its message and tool-call chunks, participate in callbacks, and behave consistently across invoke, async invoke, stream, and async stream. The consumer response endpoint used a different authentication and event model. The package exists in the translation layer between those expectations.
The difficult edge was streamed tool calling. A tool call arrives across several server-sent events, so the adapter has to preserve call identity and partial arguments, emit useful chunks as data arrives, and still reconstruct the final LangChain tool call correctly.
Diagram · select to open the full view
Text description of this diagram
A LangChain or LangGraph application calls ChatCodexOAuth using the familiar chat-model contract: messages, tool schemas, synchronous or asynchronous invocation, and callbacks. The adapter translates those inputs to the consumer response request shape and authenticates through a locally stored PKCE OAuth session.
The response surface returns server-sent events, tool calls, and usage metadata. The adapter reconstructs those events into LangChain message chunks and complete tool calls before returning them to the caller.
What had to line up
- 01
Local OAuth lifecycle
PKCE authorization, callback handling, manual fallback, credential storage, and refresh behavior had to work without an API key.
- 02
Messages and tools
Framework messages and tool schemas needed a stable translation into the endpoint request format.
- 03
Streaming state
Server-sent events had to become LangChain chunks while preserving partial tool calls and final response metadata.
- 04
Framework compatibility
The adapter supported sync, async, structured output, stop sequences, callbacks, and LangGraph usage rather than only a bespoke demo path.
This package was for local, single-user experimentation. It was not designed for account sharing, production hosting, or multi-user services, and the consumer endpoint could change independently of the package. The repository remains public evidence, but the integration is now legacy.
03
Result
What came of it
Something similar in mind?
If this is close to a problem you have, the fastest thing is usually a short conversation about what you are actually trying to change.
Discuss a project