Skip to content

Commit 76e5871

Browse files
sejoriclaude
andcommitted
docs: add Doubleword as integration provider
Add provider overview, chat model, and embeddings integration pages for Doubleword, an AI model gateway providing unified routing, management, and security for inference across multiple providers. Package: langchain-doubleword Classes: ChatDoubleword, ChatDoublewordBatch, DoublewordEmbeddings, DoublewordEmbeddingsBatch Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5525bc4 commit 76e5871

File tree

3 files changed

+250
-0
lines changed

3 files changed

+250
-0
lines changed
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
---
2+
title: "ChatDoubleword integration"
3+
sidebarTitle: Doubleword
4+
description: "Integrate with the ChatDoubleword chat model using LangChain Python."
5+
---
6+
7+
This will help you get started with Doubleword [chat models](/oss/langchain/models). [Doubleword](https://doubleword.ai/) is an AI model gateway and control layer that provides unified routing, management, and security for inference across multiple model providers.
8+
9+
The `langchain-doubleword` package provides two chat model classes:
10+
11+
- **`ChatDoubleword`**: Real-time chat completions via the Doubleword gateway.
12+
- **`ChatDoublewordBatch`**: Cost-optimized batched completions using Doubleword's batch API. Uses `autobatcher` to transparently collect concurrent calls into batch submissions.
13+
14+
## Overview
15+
16+
### Integration details
17+
18+
| Class | Package | Serializable | JS/TS Support | Downloads | Latest Version |
19+
| :--- | :--- | :---: | :---: | :---: | :---: |
20+
| `ChatDoubleword` | `langchain-doubleword` | beta || <a href="https://pypi.org/project/langchain-doubleword/" target="_blank"><img src="https://static.pepy.tech/badge/langchain-doubleword/month" alt="Downloads per month" noZoom height="100" class="rounded" /></a> | <a href="https://pypi.org/project/langchain-doubleword/" target="_blank"><img src="https://img.shields.io/pypi/v/langchain-doubleword?style=flat-square&label=%20&color=orange" alt="PyPI - Latest version" noZoom height="100" class="rounded" /></a> |
21+
22+
### Model features
23+
24+
| [Tool calling](/oss/langchain/tools) | [Structured output](/oss/langchain/structured-output) | [Image input](/oss/langchain/messages#multimodal) | Audio input | Video input | [Token-level streaming](/oss/langchain/streaming/) | Native async | [Token usage](/oss/langchain/models#token-usage) | [Logprobs](/oss/langchain/models#log-probabilities) |
25+
| :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
26+
||||||||||
27+
28+
## Setup
29+
30+
To access models via Doubleword you'll need a Doubleword account and an API key. Visit the [Doubleword documentation](https://docs.doubleword.ai) to get started.
31+
32+
### Installation
33+
34+
The LangChain Doubleword integration lives in the `langchain-doubleword` package:
35+
36+
<CodeGroup>
37+
```bash pip
38+
pip install -U langchain-doubleword
39+
```
40+
```bash uv
41+
uv add langchain-doubleword
42+
```
43+
</CodeGroup>
44+
45+
### Credentials
46+
47+
Generate an API key from your Doubleword dashboard and set the `DOUBLEWORD_API_KEY` environment variable:
48+
49+
```python
50+
import getpass
51+
import os
52+
53+
if not os.getenv("DOUBLEWORD_API_KEY"):
54+
os.environ["DOUBLEWORD_API_KEY"] = getpass.getpass("Enter your Doubleword API key: ")
55+
```
56+
57+
You can also pass the key directly via the `api_key` parameter or configure it in `~/.dw/credentials.toml`.
58+
59+
To enable automated tracing of your model calls, set your [LangSmith](/langsmith/home) API key:
60+
61+
```python
62+
os.environ["LANGSMITH_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")
63+
os.environ["LANGSMITH_TRACING"] = "true"
64+
```
65+
66+
## Instantiation
67+
68+
Now we can instantiate our model object and generate chat completions:
69+
70+
```python
71+
from langchain_doubleword import ChatDoubleword
72+
73+
model = ChatDoubleword(
74+
model="gpt-4o",
75+
temperature=0,
76+
max_tokens=1024,
77+
max_retries=2,
78+
# api_key="...", # if not using DOUBLEWORD_API_KEY env var
79+
)
80+
```
81+
82+
---
83+
84+
## Invocation
85+
86+
```python
87+
messages = [
88+
(
89+
"system",
90+
"You are a helpful assistant that translates English to French. Translate the user sentence.",
91+
),
92+
("human", "I love programming."),
93+
]
94+
ai_msg = model.invoke(messages)
95+
ai_msg.content
96+
```
97+
98+
```text
99+
"J'adore la programmation."
100+
```
101+
102+
---
103+
104+
## Streaming
105+
106+
```python
107+
for chunk in model.stream("Write a short poem about the sea."):
108+
print(chunk.text, end="", flush=True)
109+
```
110+
111+
---
112+
113+
## Tool calling
114+
115+
Doubleword supports OpenAI-compatible tool calling. You can use `bind_tools` to pass Pydantic classes, dict schemas, LangChain tools, or functions.
116+
117+
```python
118+
from pydantic import BaseModel, Field
119+
120+
121+
class GetWeather(BaseModel):
122+
"""Get the current weather in a given location"""
123+
124+
location: str = Field(description="The city and state, e.g. San Francisco, CA")
125+
126+
127+
model_with_tools = model.bind_tools([GetWeather])
128+
ai_msg = model_with_tools.invoke("What is the weather like in San Francisco?")
129+
ai_msg.tool_calls
130+
```
131+
132+
```text
133+
[{'name': 'GetWeather',
134+
'args': {'location': 'San Francisco, CA'},
135+
'id': 'call_abc123',
136+
'type': 'tool_call'}]
137+
```
138+
139+
For more on binding tools and tool call outputs, head to the [tool calling](/oss/langchain/tools) docs.
140+
141+
---
142+
143+
## Batch processing
144+
145+
`ChatDoublewordBatch` uses Doubleword's batch API to transparently collect concurrent calls into batch submissions at reduced cost. This is useful for high-throughput workloads where real-time responses are not required.
146+
147+
```python
148+
from langchain_doubleword import ChatDoublewordBatch
149+
150+
batch_model = ChatDoublewordBatch(
151+
model="gpt-4o",
152+
temperature=0,
153+
)
154+
155+
# Calls are automatically batched behind the scenes
156+
result = batch_model.invoke("Summarize the theory of relativity in one sentence.")
157+
result.content
158+
```
159+
160+
---
161+
162+
## API reference
163+
164+
For detailed documentation and source code, visit the [`langchain-doubleword` GitHub repository](https://github.com/doublewordai/langchain-doubleword).
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
title: "Doubleword Embeddings integration"
3+
description: "Integrate with the Doubleword embedding model using LangChain Python."
4+
---
5+
6+
[Doubleword](https://doubleword.ai/) is an AI model gateway that provides unified routing across multiple model providers. The `langchain-doubleword` package provides two embedding classes:
7+
8+
- **`DoublewordEmbeddings`**: Real-time embedding generation via the Doubleword gateway.
9+
- **`DoublewordEmbeddingsBatch`**: Cost-optimized batched embeddings using Doubleword's batch API.
10+
11+
## Setup
12+
13+
Install the package and set your API key:
14+
15+
<CodeGroup>
16+
```bash pip
17+
pip install -U langchain-doubleword
18+
```
19+
```bash uv
20+
uv add langchain-doubleword
21+
```
22+
</CodeGroup>
23+
24+
```python
25+
import getpass
26+
import os
27+
28+
if not os.getenv("DOUBLEWORD_API_KEY"):
29+
os.environ["DOUBLEWORD_API_KEY"] = getpass.getpass("Enter your Doubleword API key: ")
30+
```
31+
32+
## Usage
33+
34+
```python
35+
from langchain_doubleword import DoublewordEmbeddings
36+
37+
embeddings = DoublewordEmbeddings(model="text-embedding-3-small")
38+
39+
# Embed a single query
40+
query_embedding = embeddings.embed_query("What is the meaning of life?")
41+
42+
# Embed multiple documents
43+
doc_embeddings = embeddings.embed_documents(
44+
["Document one.", "Document two.", "Document three."]
45+
)
46+
```
47+
48+
## Batch embeddings
49+
50+
For high-throughput workloads, use `DoublewordEmbeddingsBatch` to automatically batch concurrent embedding requests at reduced cost:
51+
52+
```python
53+
from langchain_doubleword import DoublewordEmbeddingsBatch
54+
55+
batch_embeddings = DoublewordEmbeddingsBatch(model="text-embedding-3-small")
56+
doc_embeddings = batch_embeddings.embed_documents(
57+
["Document one.", "Document two.", "Document three."]
58+
)
59+
```
60+
61+
## API reference
62+
63+
For detailed documentation and source code, visit the [`langchain-doubleword` GitHub repository](https://github.com/doublewordai/langchain-doubleword).
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: "Doubleword integrations"
3+
description: "Route AI inference through Doubleword's unified gateway using LangChain Python."
4+
sidebarTitle: "Doubleword"
5+
---
6+
7+
[Doubleword](https://doubleword.ai/) is an AI model gateway and control layer that provides unified routing, management, and security for inference across multiple model providers. It exposes an OpenAI-compatible API with features like per-key rate limiting, request logging, and cost-optimized batch processing.
8+
9+
## Chat models
10+
11+
<Columns cols={2}>
12+
<Card title="ChatDoubleword" href="/oss/integrations/chat/doubleword" cta="Get started" icon="message" arrow>
13+
Real-time chat completions routed through the Doubleword gateway.
14+
</Card>
15+
</Columns>
16+
17+
## Embeddings
18+
19+
<Columns cols={2}>
20+
<Card title="DoublewordEmbeddings" href="/oss/integrations/embeddings/doubleword" cta="Get started" icon="grid" arrow>
21+
Generate embeddings through the Doubleword gateway.
22+
</Card>
23+
</Columns>

0 commit comments

Comments
 (0)