An integration package connecting Crusoe AI and LangChain
Project description
🦜🔗 LangChain × Crusoe AI
This package provides LangChain integrations for Crusoe AI's Managed Inference service, giving you access to leading open-source models powered by Crusoe's proprietary MemoryAlloy™ inference engine.
Features
- OpenAI-compatible API: Drop-in replacement via
BaseChatOpenAI - Leading open-source models: Llama 3.3, DeepSeek V3/R1, Qwen3, Gemma 3, Kimi-K2, GPT-OSS-120B
- Full LangChain support: Streaming, async, tool calling, structured output
- Ultra-low latency: Powered by MemoryAlloy cluster-wide KV cache technology
- LangSmith integration: Built-in tracing and observability
Installation
pip install -U langchain-crusoe
Setup
- Create an account at Crusoe Cloud
- Generate an Inference API key in the Security tab
- Set your API key:
export CRUSOE_API_KEY="your-api-key"
Quick Start
from langchain_crusoe import ChatCrusoe
llm = ChatCrusoe(
model="meta-llama/Llama-3.3-70B-Instruct",
temperature=0,
max_tokens=1024,
)
# Simple invocation
response = llm.invoke("Explain quantum computing in one paragraph.")
print(response.content)
# Streaming
for chunk in llm.stream("Write a haiku about open source."):
print(chunk.content, end="", flush=True)
Available Models
| Model | Provider | Context Length |
|---|---|---|
meta-llama/Llama-3.3-70B-Instruct |
Meta | 128k |
openai/gpt-oss-120b |
OpenAI | 128k |
deepseek-ai/DeepSeek-V3-0324 |
DeepSeek | 160k |
deepseek-ai/DeepSeek-R1-0528 |
DeepSeek | 160k |
deepseek-ai/DeepSeek-V3.1 |
DeepSeek | 160k |
Qwen/Qwen3-235B-A22B |
Qwen | 131k |
google/gemma-3-12b-it |
128k | |
moonshotai/Kimi-K2-Thinking |
Moonshot AI | 131k |
See the latest model list at the Crusoe Intelligence Foundry.
Advanced Usage
Tool Calling
from pydantic import BaseModel, Field
class GetWeather(BaseModel):
"""Get current weather for a location."""
location: str = Field(description="City and state, e.g. San Francisco, CA")
llm_with_tools = llm.bind_tools([GetWeather])
response = llm_with_tools.invoke("What's the weather in Seattle?")
print(response.tool_calls)
Structured Output
from pydantic import BaseModel
class Summary(BaseModel):
title: str
key_points: list[str]
sentiment: str
structured_llm = llm.with_structured_output(Summary)
result = structured_llm.invoke("Summarize the benefits of open-source AI models.")
Async Support
import asyncio
async def main():
response = await llm.ainvoke("Hello, async world!")
print(response.content)
asyncio.run(main())
Project ID
Optionally set a Crusoe Project ID for usage attribution:
llm = ChatCrusoe(
model="meta-llama/Llama-3.3-70B-Instruct",
crusoe_project_id="my-project-id",
)
Or via environment variable:
export CRUSOE_PROJECT_ID="my-project-id"
Configuration
| Parameter | Env Variable | Default | Description |
|---|---|---|---|
api_key |
CRUSOE_API_KEY |
— | Your Crusoe inference API key (required) |
model |
— | meta-llama/Llama-3.3-70B-Instruct |
Model to use |
crusoe_api_base |
CRUSOE_API_BASE |
https://api.crusoe.ai/v1 |
API endpoint |
crusoe_project_id |
CRUSOE_PROJECT_ID |
None |
Project ID for attribution |
temperature |
— | 0.7 (inherited) |
Sampling temperature |
max_tokens |
— | None |
Max tokens to generate |
timeout |
— | None |
Request timeout |
max_retries |
— | 2 |
Max retry attempts |
Development
# Clone the repo
git clone https://github.com/langchain-ai/langchain-crusoe.git
cd langchain-crusoe/libs/crusoe
# Install dependencies
poetry install --with lint,typing,test,test_integration
# Run unit tests
make tests
# Run integration tests (requires CRUSOE_API_KEY)
make integration_tests
# Run linting
make lint
Links
- Crusoe Cloud Console
- Crusoe Managed Inference Docs
- LangChain Documentation
- API Reference (available after package is published)
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_crusoe-0.1.0.tar.gz.
File metadata
- Download URL: langchain_crusoe-0.1.0.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.11.14 Darwin/24.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c9afcbfc8a214a35122745fcfa205b604127a73f2ef31b97f055a0461b7018c
|
|
| MD5 |
9c38ee5fb54c62066a798430519066a8
|
|
| BLAKE2b-256 |
d701e4ba74edc44059c3b9e66ec1e5d5aa4ea305da5a89b2fed84b0d5bb1ab8d
|
File details
Details for the file langchain_crusoe-0.1.0-py3-none-any.whl.
File metadata
- Download URL: langchain_crusoe-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.11.14 Darwin/24.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9312869ef056545393869d54d59ca5532cd37e2945d766e1b1c43cbe55cfac68
|
|
| MD5 |
cdff3c4564399f20e048799ac8cc41eb
|
|
| BLAKE2b-256 |
3475cd86f19a23c6884c4ded8e1afe9662c840f8d1625c6494de317a5ad83c46
|