Skip to main content

langchain-apimart

APIMart chat models for LangChain Python.

APIMart serves many hosted models (GPT, Claude, DeepSeek, Qwen, GLM, Grok and others) behind one OpenAI-compatible Chat Completions API. ChatAPIMart is a thin subclass of ChatOpenAI with APIMart defaults, so it supports streaming, tool calling, structured output and async like any LangChain chat model.

Installation

pip install -U langchain-apimart

Create an API key at apimart.ai and export it:

export APIMART_API_KEY="your-api-key"

Usage

from langchain_apimart import ChatAPIMart

llm = ChatAPIMart(model="deepseek-v4-flash", temperature=0)
print(llm.invoke("Name three prime numbers.").content)

Switch models by changing the model string, for example gpt-5.5, claude-sonnet-5-5, qwen3.7-plus, glm-5.3 or grok-4.7. See apimart.ai/model for the full list.

Streaming

for chunk in llm.stream("Write a haiku about the sea."):
    print(chunk.content, end="", flush=True)

Token usage is included in streamed responses and is counted once per response.

Tool calling

from pydantic import BaseModel, Field


class GetWeather(BaseModel):
    """Get the current weather for a city."""

    city: str = Field(description="City name")


msg = llm.bind_tools([GetWeather]).invoke("What's the weather in Paris?")
print(msg.tool_calls)

Structured output

class Joke(BaseModel):
    setup: str
    punchline: str


joke = llm.with_structured_output(Joke).invoke("Tell me a joke about cats.")

with_structured_output defaults to method="function_calling", which works across APIMart models. method="json_schema" is honored only by some models; pass it explicitly when you know the model supports it.

Configuration

Argument Environment variable Default
api_key APIMART_API_KEY required
base_url APIMART_API_BASE https://api.apimart.ai/api/v1
model deepseek-v4-flash

All other ChatOpenAI arguments (temperature, max_tokens, timeout, max_retries, ...) work as usual. The Responses API is not used.

Development

pip install -e ".[test]"
pytest                                   # offline unit tests
APIMART_API_KEY=... pytest tests/integration_tests   # real API calls

License

MIT

Metadata

Release files for langchain-apimart 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-apimart 0.1.0
File Size Uploaded Provenance Actions
langchain_apimart-0.1.0.tar.gz 7.2 kB Without provenance Details for langchain_apimart-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for langchain-apimart 0.1.0
File Interpreter ABI Platform Actions
langchain_apimart-0.1.0-py3-none-any.whl Python 3 none any Details for langchain_apimart-0.1.0-py3-none-any.whl

Total release size: 13.2 kB

Release files / langchain_apimart-0.1.0.tar.gz

Download URL langchain_apimart-0.1.0.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4ad35fee42efd972b3c9af2c8831e2ed1a06326544884c082889d04be41268cb
BLAKE2b-256 checksum
How to use checksums
fc996870471d6312cce5eac0b77c1bcb43c6fe2ce657432be56ba2d4133763cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

Release files / langchain_apimart-0.1.0-py3-none-any.whl

Download URL langchain_apimart-0.1.0-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d0380c8b363ccc2a5ad36e821c1387093e6be9f494829069487fdc70772d0557
BLAKE2b-256 checksum
How to use checksums
e27ffb3ad041e97feceb96c10a3df2f23248f887a82489a37fb0cab3beab26e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

Security for langchain-apimart 0.1.0

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page