langchain-pi
Native LangChain chat models for OpenAI Codex (ChatGPT Plus/Pro subscription OAuth), Claude (Claude Code 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 Claude Code: the Claude Code CLI logged in once (
~/.claude/.credentials.json) - 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")
claude = create_chat("claude-code", "claude-sonnet-4-6")
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.
Claude Code (Anthropic subscription)
ChatClaudeCode talks to the Anthropic Messages API authenticated with the
Claude Code OAuth session already on the machine (~/.claude/.credentials.json),
billing requests against your Claude Code subscription — no API key. It reads and
refreshes the token in place (with a claude CLI fallback).
from langchain_pi import ChatClaudeCode, create_chat
chat = create_chat("claude-code", "claude-sonnet-4-6")
print(chat.invoke("Hello!").content)
# Or construct directly, with options:
opus = ChatClaudeCode(model="claude-opus-4-8", reasoning="medium")
Models: claude-opus-4-8, claude-opus-4-7, claude-sonnet-4-6,
claude-haiku-4-5. Reasoning uses adaptive thinking on Opus 4.8/4.7 and a token
budget on Sonnet 4.6 (Haiku has no reasoning). The 1M-context beta is opt-in
via long_context=True; the subscription rejects long-context requests without
extra credits otherwise. Tool calling and streaming work as with ChatCodex.
Using a subscription OAuth session from a third-party app may violate Anthropic's terms and risk your account. See the
pi-claude-code-authREADME before relying on this.
License
MIT
Metadata
Release files for langchain-pi 0.6.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| langchain_pi-0.6.1.tar.gz | 266.0 kB | Without provenance | Details for langchain_pi-0.6.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| langchain_pi-0.6.1-py3-none-any.whl | Python 3 | none | any | Details for langchain_pi-0.6.1-py3-none-any.whl |
Total release size: 299.1 kB
Release files / langchain_pi-0.6.1.tar.gz
| Download URL | langchain_pi-0.6.1.tar.gz |
|---|---|
| Size | 266.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a96c2b3100358cf76051c1409f0431b1e13f853fe95b22704fcc0613708da3b8
|
|
BLAKE2b-256 checksum How to use checksums |
4bfbd2f04c8e6abb65e8107da37ab66557cad924d195beca1650edd12faa5f95
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / langchain_pi-0.6.1-py3-none-any.whl
| Download URL | langchain_pi-0.6.1-py3-none-any.whl |
|---|---|
| Size | 33.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
46f730210a1644c9dc0df5e91034ecdc48274ecab794e97bcd46411759da0a3c
|
|
BLAKE2b-256 checksum How to use checksums |
73e90de678a07362ffdaf086bfa858869c5e718c5870a446ffe5cbceda0aedda
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for langchain-pi 0.6.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.