Skip to main content

🦜🔗 LangChain × Crusoe AI

PyPI version License: MIT

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

  1. Create an account at Crusoe Cloud
  2. Generate an Inference API key in the Security tab
  3. 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-V4-Flash DeepSeek 1M
deepseek-ai/DeepSeek-V4-Pro DeepSeek 1M
google/gemma-4-31b-it Google 262k
moonshotai/Kimi-K2.6 Moonshot AI 256k
nvidia/Nemotron-3-Nano-30B-A3B NVIDIA 262k
nvidia/Nemotron-3-Nano-Omni-Reasoning-30B-A3B NVIDIA 262k
nvidia/Nemotron-3-Super-120B-A12B NVIDIA 262k
nvidia/Nemotron-3-Ultra-550B NVIDIA 262k
qwen/Qwen3-235B-A22B Qwen 131k
zai/GLM-5.1 Z.ai 202k
zai/GLM-5.2 Z.ai 256k

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.inference.crusoecloud.com/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/crusoecloud/crusoe-developer-hub.git
cd crusoe-developer-hub/integrations/langchain

# 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

Metadata

Release files for langchain-crusoe 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-crusoe 0.2.2
File Size Uploaded Provenance Actions
langchain_crusoe-0.2.2.tar.gz 6.3 kB Without provenance Details for langchain_crusoe-0.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for langchain-crusoe 0.2.2
File Interpreter ABI Platform Actions
langchain_crusoe-0.2.2-py3-none-any.whl Python 3 none any Details for langchain_crusoe-0.2.2-py3-none-any.whl

Total release size: 14.0 kB

Release files / langchain_crusoe-0.2.2.tar.gz

Download URL langchain_crusoe-0.2.2.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7666ad70942aace23e9b7804947a794932e7b999270ba4b67ba078cb7ece1933
BLAKE2b-256 checksum
How to use checksums
f453fa05cb3d4cc7f8d304ffc3c4f317530389d9d750de30c531ecd414014fc1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release files / langchain_crusoe-0.2.2-py3-none-any.whl

Download URL langchain_crusoe-0.2.2-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c0c4120b05f48780ed05f12fa2d7cf2fb2844354f97177cd0cf3ab027faa95e7
BLAKE2b-256 checksum
How to use checksums
43272075d21deecf0a6aca0a850902204c88d7e0a1f882852b79254407283093
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Security for langchain-crusoe 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page