> ## 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.

# ChatBaseten integration

> Integrate with the ChatBaseten chat model using LangChain Python.

This guide provides a quick overview for getting started with `ChatBaseten` [chat models](/oss/python/langchain/models).

Baseten provides inference designed for production applications. Built on the Baseten Inference Stack, these APIs deliver enterprise-grade performance and reliability for leading open-source or custom models: [https://www.baseten.co/library/](https://www.baseten.co/library/).

## Overview

### Details

| Class         | Package             | Serializable | JS support |                                              Downloads                                             |                                             Version                                             |
| :------------ | :------------------ | :----------: | :--------: | :------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------: |
| `ChatBaseten` | `langchain-baseten` |     beta     |      ❌     | ![PyPI - Downloads](https://img.shields.io/pypi/dm/langchain-baseten?style=flat-square\&label=%20) | ![PyPI - Version](https://img.shields.io/pypi/v/langchain-baseten?style=flat-square\&label=%20) |

### 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/) | Native async | [Token usage](/oss/python/langchain/models#token-usage) | [Logprobs](/oss/python/langchain/models#log-probabilities) |
| :-----------------------------------------: | :----------------------------------------------------------: | :------------------------------------------------------: | :---------: | :---------: | :-------------------------------------------------------: | :----------: | :-----------------------------------------------------: | :--------------------------------------------------------: |
|                      ✅                      |                               ✅                              |                             ✅                            |      ✅      |      ❌      |                             ✅                             |       ✅      |                            ✅                            |                              ❌                             |

Model APIs only support text input, while some dedicated deployments support image and audio input depending on model. Check the Baseten model library for details: [https://www.baseten.co/library/](https://www.baseten.co/library/)

***

## Setup

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

Head to [the Baseten website](https://app.baseten.co) to create an account and generate an API key. Once you've done this, set the `BASETEN_API_KEY` environment variable:

### Credentials

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

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

To enable automated <Tooltip tip="Log each step of a model's execution to debug and improve it">tracing</Tooltip> of your model calls, set your [LangSmith](/langsmith/observability) API key:

```python Enable tracing icon="flask" 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 Baseten integration lives in the `langchain-baseten` package:

<CodeGroup>
  ```python pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install -U langchain-baseten
  ```

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

***

## Instantiation

Baseten offers two ways to access chat models:

1. **Model APIs**: For access to the latest, most popular opensource models.
2. **Dedicated URLs**: Use specific model deployments with dedicated resources.

Both approaches are supported with automatic endpoint normalization.

```python Initialize with model slug icon="robot" theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_baseten import ChatBaseten

# Option 1: Use Model APIs with model slug
model = ChatBaseten(
    model="moonshotai/Kimi-K2-Instruct-0905",  # Choose from available model slugs: https://docs.baseten.co/development/model-apis/overview#supported-models
    api_key="your-api-key",  # Or set BASETEN_API_KEY env var
)
```

```python Initialize with model URL icon="link" theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_baseten import ChatBaseten

# Option 2: Use dedicated deployments with model url
model = ChatBaseten(
    model_url="https://model-<id>.api.baseten.co/environments/production/predict",
    api_key="your-api-key",  # Or set BASETEN_API_KEY env var
)
```

***

## Invocation

```python Basic invocation icon="player-play" theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
# Use the chat model
response = model.invoke("Hello, how are you?")
print(response.content)
```

```text theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
Hello! I'm doing well, thank you for asking! How about you?
```

You can also use message objects for more complex conversations:

<CodeGroup>
  ```python Dictionary format icon="book" theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  messages = [
      {"role": "system", "content": "You are a poetry expert"},
      {"role": "user", "content": "Write a haiku about spring"},
  ]
  response = model.invoke(messages)
  print(response)
  ```
</CodeGroup>

```text theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
content='Buds yawn open wide—\na robin stitches the hush\nwith threads of first light.' additional_kwargs={} response_metadata={'token_usage': {'completion_tokens': 26, 'prompt_tokens': 14, 'total_tokens': 40}, 'model_name': 'moonshotai/Kimi-K2-Instruct-0905', 'finish_reason': 'stop', 'model_provider': 'baseten'} id='run--6f7d1db7-daae-4628-a40a-2ab7323e8f15-0'
```

<Tip>
  Full guides are available on [chat model invocation types](/oss/python/langchain/models#invocation), [message types](/oss/python/langchain/messages#message-types), and [content blocks](/oss/python/langchain/messages#standard-content-blocks).
</Tip>

***

<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/baseten.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>
</div>
