LangChain Cerebras
raw JSON → 0.8.2 verified Mon Apr 27 auth: no python
An integration package that connects Cerebras AI models with the LangChain framework, currently at version 0.8.2. Releases are frequent, with minor and patch updates roughly every few weeks.
pip install langchain-cerebras Common errors
error ImportError: cannot import name 'Cerebras' from 'langchain_community' ↓
cause The Cerebras integration has been moved out of langchain-community into its own package.
fix
Install langchain-cerebras and import from there: from langchain_cerebras import Cerebras
error ModuleNotFoundError: No module named 'langchain_openai' ↓
cause langchain-cerebras depends on langchain-openai for making API calls, but it might not be installed automatically.
fix
Run: pip install langchain-openai
error TypeError: ChatCerebras.__init__() got an unexpected keyword argument 'reasoning_effort' ↓
cause Attempting to use reasoning parameters with an older version of langchain-cerebras (before 0.8.0) that doesn't support them.
fix
Upgrade langchain-cerebras to >=0.8.0: pip install --upgrade langchain-cerebras
Warnings
breaking Version 0.8.0 introduced reasoning parameters support, which may require updates to existing code if using the previous simple generation interface. ↓
fix Review the changelog and adjust calls to include additional parameters like 'reasoning_effort' if needed.
deprecated The old import path 'from langchain_community.llms import Cerebras' is deprecated in favor of 'from langchain_cerebras import Cerebras'. ↓
fix Use the new import from langchain_cerebras instead.
gotcha The library requires Python 3.11 or 3.12; Python 3.13 is not supported as of version 0.8.2. ↓
fix Use Python 3.11 or 3.12.
Imports
- Cerebras
from langchain_cerebras import Cerebras - ChatCerebras
from langchain_cerebras import ChatCerebras - CerebrasEmbeddings wrong
from langchain_community.embeddings import CerebrasEmbeddingscorrectfrom langchain_cerebras import CerebrasEmbeddings
Quickstart
import os
from langchain_cerebras import ChatCerebras
llm = ChatCerebras(
model="llama3.1-8b",
api_key=os.environ.get("CEREBRAS_API_KEY", ""),
temperature=0.7
)
response = llm.invoke("Hello, how are you?")
print(response.content)