Metadata-Version: 2.5
Name: langchain-apimart
Version: 0.1.0
Summary: APIMart chat models for LangChain Python.
Project-URL: Homepage, https://apimart.ai
Project-URL: Documentation, https://docs.apimart.ai
Project-URL: Repository, https://github.com/ApiMartAI/langchain-apimart
Project-URL: Issues, https://github.com/ApiMartAI/langchain-apimart/issues
License-Expression: MIT
License-File: LICENSE
Keywords: apimart,chat-completions,langchain,llm
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: langchain-core<2,>=1.7.7
Requires-Dist: langchain-openai<2,>=1.7.4
Requires-Dist: pydantic<3,>=2.7.4
Provides-Extra: test
Requires-Dist: httpx<1,>=0.28; extra == 'test'
Requires-Dist: langchain-tests<2,>=1.2; extra == 'test'
Requires-Dist: pytest-asyncio<2,>=1; extra == 'test'
Requires-Dist: pytest<10,>=8.4; extra == 'test'
Description-Content-Type: text/markdown

# langchain-apimart

[APIMart](https://apimart.ai) chat models for [LangChain](https://docs.langchain.com/oss/python/langchain/overview) 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

```bash
pip install -U langchain-apimart
```

Create an API key at [apimart.ai](https://apimart.ai) and export it:

```bash
export APIMART_API_KEY="your-api-key"
```

## Usage

```python
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](https://apimart.ai/model) for the full list.

### Streaming

```python
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

```python
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

```python
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

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

## License

MIT
