langchain-topxai
LangChain chat model for TopxAI, an API gateway that serves Claude, GPT, Grok, GLM, Kimi and DeepSeek models through one OpenAI-compatible endpoint at fixed USD prices per route.
Installation
pip install -U langchain-topxai
Create a key at https://ai.topxea.com/keys and set it:
export TOPXAI_API_KEY="your-api-key"
Chat models
from langchain_topxai import ChatTopxAI
model = ChatTopxAI(model="kimi-k3", temperature=0)
model.invoke("Sing a ballad of LangChain.")
model takes any text model id from https://ai.topxea.com/pricing, for example claude-sonnet-5-5, gpt-6.1-sol, grok-4.7, kimi-k3, deepseek-v4-pro or deepseek-flash. ChatTopxAI builds on langchain-openai's BaseChatOpenAI and always calls the Chat Completions API: streaming, async calls, tool calling, structured output and token usage work as they do there. For TopxAI's Responses API, use ChatOpenAI from langchain-openai with base_url="https://ai.topxea.com/v1" and use_responses_api=True.
Models that return their reasoning (for example deepseek-flash and kimi-k3) put it in additional_kwargs["reasoning_content"], also when streaming:
msg = ChatTopxAI(model="deepseek-flash").invoke("What is 17 * 3?")
msg.additional_kwargs.get("reasoning_content")
with_structured_output uses JSON Schema by default (method="json_schema", as in ChatOpenAI). Keep the default for the Claude models (claude-sonnet-5-5, claude-opus-5-5, claude-fable-5-1): they do not accept a forced tool call, so method="function_calling" fails for them.
Configuration
| Argument | Environment variable | Default |
|---|---|---|
api_key |
TOPXAI_API_KEY |
none; required. OPENAI_API_KEY is never read. |
base_url |
TOPXAI_API_BASE |
https://ai.topxea.com/v1 |
Links
- Guide: https://ai.topxea.com/docs/use-topxai-with-langchain
- Models and prices: https://ai.topxea.com/pricing
- API reference: https://ai.topxea.com/docs/api-reference
Development
make tests # unit tests, no network
make integration_tests # LangChain standard integration tests, needs TOPXAI_API_KEY
make lint type
MIT licensed. Maintained by TopXEA, the operator of TopxAI.
Metadata
Release files for langchain-topxai 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| langchain_topxai-0.1.0.tar.gz | 10.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| langchain_topxai-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.5 kB
Release files / langchain_topxai-0.1.0.tar.gz
| Download URL | langchain_topxai-0.1.0.tar.gz |
|---|---|
| Size | 10.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1cbbedf9038b6c4adb76fd2e457372084c6d86c90c868037a2a2b20b0c3e4240
|
|
BLAKE2b-256 checksum How to use checksums |
46b7200011de24b1097364ddc362e695c14bdc0c69ae4ae73a2a4af4aeb844a7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.
Transparency logRelease files / langchain_topxai-0.1.0-py3-none-any.whl
| Download URL | langchain_topxai-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d2a8d528ee8694d5494f35328eb8b177062ce3f23fdb2428a99b44da9dd440e3
|
|
BLAKE2b-256 checksum How to use checksums |
8bf6ecaa7784fb54c231fe2c9164662989e85676bef0ba416c3efea78836f178
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.
Transparency log