Native LangChain chat models for OpenAI Codex subscription OAuth and OpenCode Zen/Go — no Node sidecar.
Project description
langchain-pi
Native LangChain chat models for OpenAI Codex with ChatGPT Plus/Pro subscription OAuth and OpenCode Zen/Go. No Pi runtime, no Node sidecar.
Requirements
- Python >= 3.9
- For Codex: an
openai-codexcredential in~/.pi/agent/auth.json, or sign in withcodex-login - For paid OpenCode models:
OPENCODE_API_KEYor an explicitapi_key
Install
pip install langchain-pi
# or: uv add langchain-pi
Usage
create_chat routes the supported native providers:
from langchain_pi import create_chat
codex = create_chat("openai-codex", "gpt-5.3-codex-spark")
free = create_chat("opencode", "deepseek-v4-flash-free")
go = create_chat("opencode-go", "glm-5", api_key="...")
Or construct Codex directly:
from langchain_pi import ChatCodex
model = ChatCodex(
model="gpt-5.3-codex-spark",
reasoning="minimal",
system="You are a helpful assistant.",
)
print(model.invoke("Hello!").content)
Codex Auth
ChatCodex reads the same ~/.pi/agent/auth.json credential shape under
openai-codex, refreshes the OAuth token in place, and talks directly to
https://chatgpt.com/backend-api/codex/responses.
If no credential exists:
codex-login
codex-login --device
Tool Calling
from langchain_core.tools import tool
from langchain_pi import ChatCodex
@tool
def get_weather(city: str) -> str:
"""Get the current weather for a city."""
return f"It is sunny in {city}, 24C."
model = ChatCodex(model="gpt-5.3-codex").bind_tools([get_weather])
msg = model.invoke("What's the weather in Paris?")
print(msg.tool_calls)
tool_choice is passed through to the Codex Responses API:
forced = ChatCodex(model="gpt-5.3-codex").bind_tools(
[get_weather],
tool_choice={"type": "function", "name": "get_weather"},
)
For agent loops, keep tool_choice="auto" unless every model turn should call the
same tool.
Streaming
for chunk in model.stream("Write a haiku."):
print(chunk.content, end="")
OpenCode
ChatOpencode uses OpenCode's OpenAI-compatible endpoints through
langchain-openai.
from langchain_pi import ChatOpencode
free = ChatOpencode("deepseek-v4-flash-free")
paid = ChatOpencode("glm-5")
go = ChatOpencode("glm-5", tier="go")
Free models include deepseek-v4-flash-free, big-pickle, mimo-v2.5-free, and
nemotron-3-super-free.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_pi-0.5.0.tar.gz.
File metadata
- Download URL: langchain_pi-0.5.0.tar.gz
- Upload date:
- Size: 251.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb992375d8d030a32efc39e55fc30b663f3b013a7eb61144cd06c09dc715806c
|
|
| MD5 |
7874c987be7257eead2026c3aca8d2c6
|
|
| BLAKE2b-256 |
968d80d7b9629ee4c7a7c6087c5b1933d4f24acbf64a3187c83caf376117d2fd
|
File details
Details for the file langchain_pi-0.5.0-py3-none-any.whl.
File metadata
- Download URL: langchain_pi-0.5.0-py3-none-any.whl
- Upload date:
- Size: 19.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
186e77d243c8dba2ff40648d1028846a73ca8cfe53343afb6330b79e37cac829
|
|
| MD5 |
3a0ca21d4e24d864a99984a065cec7d2
|
|
| BLAKE2b-256 |
e9c5801495c1c7875120fb909d2377f96bb3a7ae990c78f5b86f809593bce56d
|