An integration package connecting Doubleword and LangChain / LangGraph.
Project description
langchain-doubleword
A LangChain integration package for Doubleword.
This package wires Doubleword's OpenAI-compatible inference API
(https://api.doubleword.ai/v1) into LangChain and LangGraph as both real-time
chat / embedding models and transparently-batched variants powered by
autobatcher.
The batched variants are required to access models that Doubleword exposes only via the batch API, and they cut cost on workloads that fan out many concurrent calls — typically the case in LangGraph agents.
Installation
pip install langchain-doubleword
Authentication
Three resolution paths, in precedence order:
-
Explicit constructor argument:
ChatDoubleword(model="...", api_key="sk-...")
-
Environment variable:
export DOUBLEWORD_API_KEY=sk-...
-
~/.dw/credentials.toml— the same file written by Doubleword's CLI tooling. The active account is selected by~/.dw/config.toml'sactive_accountfield, andinference_keyfrom that account is used.# ~/.dw/config.toml active_account = "work"
# ~/.dw/credentials.toml [accounts.work] inference_key = "sk-..."
To use a non-active account from your credentials file, set
DOUBLEWORD_API_KEYdirectly to that account'sinference_key— there is noaccount=selector on the model itself.
Chat models
ChatDoubleword (real-time)
Drop-in chat model. Use this in any LangChain or LangGraph workflow that
expects a BaseChatModel.
from langchain_doubleword import ChatDoubleword
llm = ChatDoubleword(model="your-model-name")
response = llm.invoke("Explain bismuth in three sentences.")
print(response.content)
ChatDoublewordBatch (transparently batched)
Same interface, but every concurrent .ainvoke() call is collected by
autobatcher and submitted via Doubleword's batch endpoint. Async-only —
sync .invoke() raises.
Use this when:
- The model you want is batch-only (some Doubleword-hosted models do not expose a real-time chat endpoint).
- You're running a LangGraph workflow with parallel branches and want ~50% cost savings via batch pricing.
import asyncio
from langchain_doubleword import ChatDoublewordBatch
llm = ChatDoublewordBatch(model="batch-only-model")
async def main():
# Concurrent calls collected into a single batch under the hood.
results = await asyncio.gather(*[
llm.ainvoke(f"Summarize chapter {i}") for i in range(50)
])
for r in results:
print(r.content)
asyncio.run(main())
Tuning autobatcher
Four autobatcher.BatchOpenAI knobs are exposed as constructor arguments:
| Argument | Default | Purpose |
|---|---|---|
batch_size |
1000 |
Submit a batch when this many requests are queued. |
batch_window_seconds |
10.0 |
Submit a batch after this many seconds even if the size cap is not reached. |
poll_interval_seconds |
5.0 |
How often autobatcher polls for batch completion. |
completion_window |
"24h" |
Doubleword batch completion window. "1h" is more expensive but faster. |
llm = ChatDoublewordBatch(
model="your-model",
batch_size=250, # smaller batches for fast-turnaround LangGraph nodes
batch_window_seconds=2.5, # don't make latency-sensitive calls wait 10s
completion_window="1h", # pay more, finish quicker
)
The same arguments are available on DoublewordEmbeddingsBatch.
ChatDoublewordAsync (1-hour flex tier)
A thin subclass of ChatDoublewordBatch pinned to Doubleword's flex
(1-hour) completion window. Backed by autobatcher.AsyncOpenAI rather
than BatchOpenAI. Use this when 24-hour batch turnaround is too slow but
realtime cost is too high — typical for fan-out workflows that need results
within minutes-to-an-hour.
import asyncio
from langchain_doubleword import ChatDoublewordAsync
llm = ChatDoublewordAsync(model="your-model") # completion_window="1h" by default
async def main():
results = await asyncio.gather(*[
llm.ainvoke(f"Summarize chapter {i}") for i in range(50)
])
for r in results:
print(r.content)
asyncio.run(main())
All the autobatcher tuning knobs above apply unchanged. The only difference
from ChatDoublewordBatch is the default completion_window ("1h" vs
"24h"); the same DoublewordEmbeddingsAsync exists on the embeddings side.
Embeddings
from langchain_doubleword import (
DoublewordEmbeddings,
DoublewordEmbeddingsAsync,
DoublewordEmbeddingsBatch,
)
embed = DoublewordEmbeddings(model="your-embedding-model")
vec = embed.embed_query("hello world")
# Or, transparently batched (24h tier):
batch_embed = DoublewordEmbeddingsBatch(model="your-embedding-model")
# vecs = await batch_embed.aembed_documents([...])
# Or on the 1h flex tier:
async_embed = DoublewordEmbeddingsAsync(model="your-embedding-model")
# vecs = await async_embed.aembed_documents([...])
Use with LangGraph
ChatDoubleword, ChatDoublewordBatch, and ChatDoublewordAsync are all standard BaseChatModel
implementations, so they slot into any LangGraph node:
from langgraph.graph import StateGraph, END
from langchain_doubleword import ChatDoublewordBatch
llm = ChatDoublewordBatch(model="your-model")
async def call_model(state):
response = await llm.ainvoke(state["messages"])
return {"messages": [response]}
graph = StateGraph(dict)
graph.add_node("model", call_model)
graph.set_entry_point("model")
graph.add_edge("model", END)
app = graph.compile()
When several model nodes execute in parallel (e.g. via Send or fan-out
edges), autobatcher collects their requests into a single batch.
Configuration
| Argument | Env var | Default |
|---|---|---|
api_key |
DOUBLEWORD_API_KEY |
required |
base_url |
DOUBLEWORD_API_BASE |
https://api.doubleword.ai/v1 |
model |
— | required |
All other arguments accepted by langchain_openai.ChatOpenAI are forwarded
unchanged (temperature, max_tokens, model_kwargs, timeout, etc.).
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_doubleword-0.2.1.tar.gz.
File metadata
- Download URL: langchain_doubleword-0.2.1.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c51197a850d50c3083688fbaa9bea646191b04c61a93127d621ebeb99a445a3
|
|
| MD5 |
9a5a147457732f4f8bdce440dbb799f3
|
|
| BLAKE2b-256 |
afcfe1d4aff4d89805cad426c44d636fb952801d6bffb320921c4f8d01eef543
|
Provenance
The following attestation bundles were made for langchain_doubleword-0.2.1.tar.gz:
Publisher:
publish.yml on doublewordai/langchain-doubleword
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langchain_doubleword-0.2.1.tar.gz -
Subject digest:
0c51197a850d50c3083688fbaa9bea646191b04c61a93127d621ebeb99a445a3 - Sigstore transparency entry: 1393669917
- Sigstore integration time:
-
Permalink:
doublewordai/langchain-doubleword@7d8fb1b7c560dbf4ede9fafc4e2a76a5dc7cd7d7 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/doublewordai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7d8fb1b7c560dbf4ede9fafc4e2a76a5dc7cd7d7 -
Trigger Event:
release
-
Statement type:
File details
Details for the file langchain_doubleword-0.2.1-py3-none-any.whl.
File metadata
- Download URL: langchain_doubleword-0.2.1-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ed93d55b2b444a48e183a574f55860371c72db70a512f4400221c8c4a4c791e
|
|
| MD5 |
93e3a4a71ab202559ca573d30384b3a3
|
|
| BLAKE2b-256 |
9188af7601ca7a362666396dd31191ed53fa8a0ed7a610047c07501623064138
|
Provenance
The following attestation bundles were made for langchain_doubleword-0.2.1-py3-none-any.whl:
Publisher:
publish.yml on doublewordai/langchain-doubleword
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langchain_doubleword-0.2.1-py3-none-any.whl -
Subject digest:
0ed93d55b2b444a48e183a574f55860371c72db70a512f4400221c8c4a4c791e - Sigstore transparency entry: 1393669996
- Sigstore integration time:
-
Permalink:
doublewordai/langchain-doubleword@7d8fb1b7c560dbf4ede9fafc4e2a76a5dc7cd7d7 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/doublewordai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7d8fb1b7c560dbf4ede9fafc4e2a76a5dc7cd7d7 -
Trigger Event:
release
-
Statement type: