Skip to main content

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-codex credential in ~/.pi/agent/auth.json, or sign in with codex-login
  • For paid OpenCode models: OPENCODE_API_KEY or an explicit api_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_pi-0.6.0.tar.gz (265.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_pi-0.6.0-py3-none-any.whl (32.5 kB view details)

Uploaded Python 3

File details

Details for the file langchain_pi-0.6.0.tar.gz.

File metadata

  • Download URL: langchain_pi-0.6.0.tar.gz
  • Upload date:
  • Size: 265.5 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for langchain_pi-0.6.0.tar.gz
Algorithm Hash digest
SHA256 e0f0e55781c4e5cd524f06d0c59ab93a68ee99ef461b9ddae9fffcc47029421b
MD5 0fdb1e525b7a2c6b22f604dba456bd64
BLAKE2b-256 f354354c1973109ad94edf8ecbbddd8c47b15d5fe84dac205374e2e065f41b3e

See more details on using hashes here.

File details

Details for the file langchain_pi-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: langchain_pi-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 32.5 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for langchain_pi-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d58a94dad007e277b9210821b4bade7816d483ef05821bd684e7c1f411bbce12
MD5 c9d450452cf929055fb3226901656026
BLAKE2b-256 e8b4f851b5692b874a4a1e9f847e4de177d7df1078ec067abea70be98b726cf8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page