Metadata-Version: 2.4
Name: langchain-thalam
Version: 0.1.0
Summary: LangChain integration for thalam. — one OpenAI-compatible endpoint for every leading AI model.
Project-URL: Homepage, https://www.thalam.ai
Project-URL: Documentation, https://www.thalam.ai/docs
Project-URL: Repository, https://github.com/thalam-ai/langchain-thalam
Project-URL: Issues, https://github.com/thalam-ai/langchain-thalam/issues
Author-email: "thalam." <press@thalam.ai>
License: Apache-2.0
License-File: LICENSE
Keywords: ai-gateway,deepseek,glm,kimi,langchain,llm,openai-compatible,qwen,thalam
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.9
Requires-Dist: langchain-core>=0.3.0
Requires-Dist: langchain-openai>=0.2.0
Requires-Dist: pydantic>=2.0.0
Description-Content-Type: text/markdown

# langchain-thalam

[LangChain](https://python.langchain.com) integration for **thalam.** — one OpenAI-compatible endpoint for every leading AI model.

Built in the UAE. Text, image, and video models from a single endpoint, with per-key spend caps and audit logs as a built-in governance layer.

- **One endpoint** — DeepSeek, Qwen, Kimi, GLM, MiniMax, Claude, GPT, Llama, Grok, Mistral and more
- **Drop-in LangChain compatibility** — every LangChain feature (streaming, tools, structured output, async) works unchanged
- **Pay per token** — no subscription, no minimums
- **AED or USD invoicing** on Enterprise contracts

## Install

```bash
pip install langchain-thalam
```

Sign up at [thalam.ai](https://www.thalam.ai) — no card required: new accounts get **$1 in starter credit** to use right away, then add a card to top up.

## Quickstart

```python
import os
from langchain_thalam import ChatThalam

os.environ["THALAM_API_KEY"] = "tl-..."

llm = ChatThalam(model="deepseek/deepseek-v3.2", temperature=0)

response = llm.invoke("Explain quantum entanglement in 2 sentences.")
print(response.content)
```

Or pass the key explicitly:

```python
from langchain_thalam import ChatThalam

llm = ChatThalam(
    model="qwen/qwen3-max",
    api_key="tl-...",
)
```

## Streaming

```python
from langchain_thalam import ChatThalam

llm = ChatThalam(model="deepseek/deepseek-v3.2")

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

## Tool calling

```python
from langchain_thalam import ChatThalam
from langchain_core.tools import tool

@tool
def get_weather(city: str) -> dict:
    """Get the weather in a city."""
    return {"temp": 32, "unit": "C", "city": city}

llm = ChatThalam(model="deepseek/deepseek-v4-pro")
llm_with_tools = llm.bind_tools([get_weather])

response = llm_with_tools.invoke("What's the weather in Dubai?")
print(response.tool_calls)
```

## Structured outputs

```python
from langchain_thalam import ChatThalam
from pydantic import BaseModel, Field

class BlogMetadata(BaseModel):
    title: str = Field(description="The post title")
    tags: list[str] = Field(description="3-5 relevant tags")

llm = ChatThalam(model="deepseek/deepseek-v3.2")
structured_llm = llm.with_structured_output(BlogMetadata)

result = structured_llm.invoke("Generate metadata for a post about MENA fintech.")
print(result.title, result.tags)
```

## Async

```python
import asyncio
from langchain_thalam import ChatThalam

async def main():
    llm = ChatThalam(model="deepseek/deepseek-v3.2")
    result = await llm.ainvoke("Hi")
    print(result.content)

asyncio.run(main())
```

## In a LangChain chain

```python
from langchain_thalam import ChatThalam
from langchain_core.prompts import ChatPromptTemplate

prompt = ChatPromptTemplate.from_messages([
    ("system", "You are a senior MENA fintech analyst. Respond concisely."),
    ("user", "{question}"),
])

llm = ChatThalam(model="deepseek/deepseek-v3.2")
chain = prompt | llm

result = chain.invoke({"question": "Top 3 fintech trends in the UAE in 2026?"})
print(result.content)
```

## Available models

The full live catalog is at [thalam.ai/models](https://www.thalam.ai/models) or via:

```python
import os, requests
r = requests.get(
    "https://api.thalam.ai/v1/models",
    headers={"Authorization": f"Bearer {os.environ['THALAM_API_KEY']}"},
)
for m in r.json()["data"]:
    print(m["id"], "-", m["display_name"], "-", m["category"])
```

Common text-model IDs:

| ID                                                | Notes                              |
|---------------------------------------------------|------------------------------------|
| `deepseek/deepseek-v4-pro`                        | Flagship reasoning, 1M context     |
| `deepseek/deepseek-v4-flash`                      | Fast, low-cost                     |
| `deepseek/deepseek-v3.2`                          | Strong general intelligence        |
| `deepseek/deepseek-r1-0528`                       | Open reasoning                     |
| `qwen/qwen3-max`                                  | Frontier multilingual + Arabic     |
| `qwen/qwen3.5-397b-a17b`                          | Large MoE, top open quality        |
| `qwen/qwen3-coder-480b-a35b-instruct`             | Coding flagship                    |
| `zhipu/glm-5.1`                                   | Multimodal-capable                 |
| `moonshotai/kimi-k2-thinking`                     | Long-context reasoning             |
| `anthropic/claude-opus-4.8`                       | Flagship reasoning (via gateway)   |
| `anthropic/claude-opus-4.7`                       | Premium reasoning (via gateway)    |
| `anthropic/claude-sonnet-4.6`                     | Balanced (via gateway)             |
| `openai/gpt-5.4`                                  | OpenAI flagship (via gateway)      |
| `xai/grok-4`                                      | xAI flagship                       |
| `meta-llama/llama-3.3-70b-instruct`               | Open Llama                         |
| `meta-llama/llama-4-maverick-17b-128e-instruct-fp8` | Llama 4 flagship                 |

## Configuration

```python
from langchain_thalam import ChatThalam

llm = ChatThalam(
    model="deepseek/deepseek-v3.2",
    api_key="tl-...",                              # default: env THALAM_API_KEY
    base_url="https://api.thalam.ai/v1",            # default
    temperature=0.7,
    max_tokens=512,
    timeout=60,
    max_retries=2,
)
```

Every keyword argument that `langchain_openai.ChatOpenAI` accepts is supported.

## Links

- [thalam.ai](https://www.thalam.ai)
- [Documentation](https://www.thalam.ai/docs)
- [Model catalog](https://www.thalam.ai/models)
- [LangChain docs](https://python.langchain.com)

## License

Apache-2.0
