LangChain
Python ChatOpenAI with explicit Chat Completions.
Manual setup
1. Inspect the existing Python environment and package manager. Add langchain-openai only with authorization, preserving constraints and lockfiles. For a new isolated example use the venv commands below; Windows uses .venv\Scripts\python.exe instead of .venv/bin/python.
2. Save the Python example as zrelay_chat.py and adapt only the project model-construction point. Import from langchain_openai. Use a Grok/Flex key for grok-4.7 Chat Completions; the pool comes from the key, not an invented request parameter.
3. The example asks for the key locally only when absent. use_responses_api=False forces Chat Completions; max_tokens=256 is mapped to max_completion_tokens by current code. Do not supply both or put this standard limit in extra_body.
4. Compile syntax and inspect installed imports without invoking generation. The invoke line is commented: uncomment only for an authorized billed request. max_retries=0 prevents automatic test retries and timeout=60 bounds waiting.
Configuration and commands
python -m venv .venv
.venv/bin/python -m pip install langchain-openaiimport getpass
import os
from langchain_openai import ChatOpenAI
if not os.environ.get("ZRELAY_API_KEY"):
os.environ["ZRELAY_API_KEY"] = getpass.getpass("Zrelay API key: ")
llm = ChatOpenAI(
model="grok-4.7",
base_url="https://api.zrelay.net/v1",
api_key=os.environ["ZRELAY_API_KEY"],
use_responses_api=False,
max_tokens=256,
max_retries=0,
timeout=60,
)
# Uncomment only when ready to make a billed request:
# print(llm.invoke("Reply with one short greeting.").content)Alternative: ask an AI assistant
Copy this complete prompt into your coding assistant. It describes configuration work; installation and paid tests need your authorization.
Integrate Zrelay into this Python LangChain project. Detect OS, Python, package manager, virtual environment, installed langchain-openai version and the existing model-construction point. Read https://docs.langchain.com/oss/python/integrations/chat/openai and https://keys.zrelay.net/api/catalog. Preserve existing settings, providers, dependency constraints and lockfiles. Ask before installing or upgrading dependencies. Use langchain_openai.ChatOpenAI with base_url="https://api.zrelay.net/v1", api_key=os.environ["ZRELAY_API_KEY"], use_responses_api=False, max_tokens=256 and max_retries=0. Select an enabled Chat Completions model matching my provider/pool; grok-4.7 requires a matching Grok key. Verify these constructor options against the installed version. Request credentials only through local hidden input or existing secret storage; never read, display, log, commit or put the key in this conversation. Validate imports and syntax without inference. Ask for explicit consent before any paid request. Do not assume streaming, tool loops, hosted tools or provider-specific response fields work. Report files changed, checks performed and remaining runtime validation.Limits and verification
The catalog ceiling is 4096. Current upstream master is mutable; verify constructor options against the installed version. Nonstandard provider fields may not survive translation. Construction/import checks do not test authentication, access, streaming, hosted tools or tool loops.
These recipes were reviewed against documentation and public catalog data. No client installation, authenticated request, paid inference, streaming or tool loop was executed. Validate configuration first; a later short text test does not establish complete agent compatibility.
Recheck the live catalog and your key’s provider/pool. The reviewed examples have 128000 input and 4096 output maxima unless a client limitation above prevents controlling the request. Never print, log or commit credentials.
Official sources
Documentation checked 2026-11-09; mutable sources can differ from your installed version.
https://docs.langchain.com/oss/python/integrations/chat
https://docs.langchain.com/oss/python/integrations/chat/openai
Questions about your integration? support@zrelay.net