> ## Documentation Index
> Fetch the complete documentation index at: https://docs.langchain.com/llms.txt
> Use this file to discover all available pages before exploring further.

# ChatCrusoe integration

> Integrate with the ChatCrusoe chat model using LangChain Python.

This page will help you get started with Crusoe AI [chat models](/oss/python/langchain/models). For detailed documentation of all ChatCrusoe features and configurations, head to the [Crusoe managed inference docs](https://docs.crusoecloud.com/managed-inference/overview).

[Crusoe AI](https://www.crusoe.ai/) provides high-performance managed inference for [leading open-source models](https://docs.crusoecloud.com/managed-inference/overview) via the Crusoe Intelligence Foundry, powered by proprietary MemoryAlloy™ technology for ultra-low latency and high throughput.

## Overview

### Integration details

| Class                                                                 | Package                                                        | Serializable | JS support |                                                   Downloads                                                   |                                                    Version                                                   |
| :-------------------------------------------------------------------- | :------------------------------------------------------------- | :----------: | :--------: | :-----------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------: |
| [ChatCrusoe](https://docs.crusoecloud.com/managed-inference/overview) | [langchain-crusoe](https://pypi.org/project/langchain-crusoe/) |     beta     |      ❌     | ![PyPI - Downloads](https://img.shields.io/pypi/dm/langchain-crusoe?style=flat-square\&label=%20\&color=blue) | ![PyPI - Version](https://img.shields.io/pypi/v/langchain-crusoe?style=flat-square\&label=%20\&color=orange) |

### Model features

| [Tool calling](/oss/python/langchain/tools) | [Structured output](/oss/python/langchain/structured-output) | [Image input](/oss/python/langchain/messages#multimodal) | Audio input | Video input | [Token-level streaming](/oss/python/langchain/streaming#llm-tokens) | Native async | [Token usage](/oss/python/langchain/models#token-usage) | [Logprobs](/oss/python/langchain/models#log-probabilities) |
| :-----------------------------------------: | :----------------------------------------------------------: | :------------------------------------------------------: | :---------: | :---------: | :-----------------------------------------------------------------: | :----------: | :-----------------------------------------------------: | :--------------------------------------------------------: |
|                      ✅                      |                               ✅                              |                             ❌                            |      ❌      |      ❌      |                                  ✅                                  |       ✅      |                            ✅                            |                              ❌                             |

## Setup

To access Crusoe models you'll need to create a Crusoe Cloud account, get an Inference API key, and install the `langchain-crusoe` integration package.

### Credentials

Head to the [Crusoe Cloud Console](https://console.crusoecloud.com/) to sign up. Then navigate to the **Security** tab and select **Inference API Key** to generate your key. Once you've done this, set the CRUSOE\_API\_KEY environment variable:

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import getpass
import os

if "CRUSOE_API_KEY" not in os.environ:
    os.environ["CRUSOE_API_KEY"] = getpass.getpass("Enter your Crusoe API key: ")
```

To enable automated tracing of your model calls, set your [LangSmith](/langsmith/observability) API key:

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
os.environ["LANGSMITH_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")
os.environ["LANGSMITH_TRACING"] = "true"
```

### Installation

The LangChain Crusoe integration is included in the `langchain-crusoe` package:

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install -qU langchain-crusoe
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add langchain-crusoe
  ```
</CodeGroup>

## Instantiation

Now we can instantiate our model object and generate chat completions:

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_crusoe import ChatCrusoe

llm = ChatCrusoe(
    model="meta-llama/Llama-3.3-70B-Instruct",
    temperature=0,
    max_tokens=None,
    timeout=None,
    max_retries=2,
    # api_key="...",  # if not set via CRUSOE_API_KEY env var
    # other params...
)
```

### Available models

Crusoe serves leading open-source models via the Intelligence Foundry. See the [full model list](https://docs.crusoecloud.com/managed-inference/overview) for the latest availability.

| 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`             | Google      |      128k      |
| `moonshotai/Kimi-K2-Thinking`       | Moonshot AI |      131k      |

## Invocation

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
messages = [
    (
        "system",
        "You are a helpful assistant that translates English to French. Translate the user sentence.",
    ),
    ("human", "I love programming."),
]
ai_msg = llm.invoke(messages)
ai_msg
```

```text theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
AIMessage(content="J'adore la programmation.", response_metadata={'token_usage': {'completion_tokens': 9, 'prompt_tokens': 35, 'total_tokens': 44}, 'model_name': 'meta-llama/Llama-3.3-70B-Instruct', 'system_fingerprint': None, 'finish_reason': 'stop', 'logprobs': None}, id='run-...', usage_metadata={'input_tokens': 35, 'output_tokens': 9, 'total_tokens': 44})
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
print(ai_msg.content)
```

```text theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
J'adore la programmation.
```

## Chaining

We can [chain](/oss/python/langchain/overview) our model with a prompt template like so:

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_core.prompts import ChatPromptTemplate

prompt = ChatPromptTemplate.from_messages(
    [
        (
            "system",
            "You are a helpful assistant that translates {input_language} to {output_language}.",
        ),
        ("human", "{input}"),
    ]
)

chain = prompt | llm
chain.invoke(
    {
        "input_language": "English",
        "output_language": "German",
        "input": "I love programming.",
    }
)
```

```text theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
AIMessage(content='Ich liebe Programmieren.', response_metadata={...}, id='run-...')
```

## Streaming

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
stream = llm.stream_events(messages, version="v3")
for token in stream.text:
    print(token, end="", flush=True)
```

## Tool calling

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from pydantic import BaseModel, Field

class GetWeather(BaseModel):
    """Get the current weather in a given location."""
    location: str = Field(description="City and state, e.g. San Francisco, CA")

llm_with_tools = llm.bind_tools([GetWeather])
ai_msg = llm_with_tools.invoke("What's the weather like in San Francisco?")
print(ai_msg.tool_calls)
```

## Structured output

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from pydantic import BaseModel, Field
from typing import Optional

class Joke(BaseModel):
    """Joke to tell user."""
    setup: str = Field(description="The setup of the joke")
    punchline: str = Field(description="The punchline to the joke")
    rating: Optional[int] = Field(description="How funny the joke is, from 1 to 10")

structured_llm = llm.with_structured_output(Joke)
structured_llm.invoke("Tell me a joke about cats")
```

```text theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
Joke(setup='Why was the cat sitting on the computer?', punchline='To keep an eye on the mouse!', rating=7)
```

## API reference

For detailed documentation of all ChatCrusoe features and configurations, head to the [Crusoe managed inference docs](https://docs.crusoecloud.com/managed-inference/overview).

***

<div className="source-links">
  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>

  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/chat/crusoe.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>
</div>
