LangChain Nebius Integration
This package provides LangChain integration for Nebius AI Studio, enabling seamless use of Nebius AI Studio's chat and embedding models within LangChain. It offers classes for chat models (ChatNebius), embedding models (NebiusEmbeddings), and a retriever (NebiusRetriever), facilitating common LLM application patterns like RAG. The current version is 0.1.3.
Warnings
- gotcha API Key Management: Nebius requires an API key for authentication. It's recommended to set it as an environment variable named `NEBIUS_API_KEY` rather than passing it directly in code for security reasons.
- gotcha LangChain Version Compatibility: As the LangChain ecosystem (especially `langchain-core`) evolves rapidly, ensure your installed `langchain-nebius` version is compatible with your core LangChain packages to avoid import errors or unexpected behavior.
- gotcha Model String Variations: The `model` parameter for `ChatNebius` and `NebiusEmbeddings` expects a specific string identifier. These identifiers may vary or new models may become available. Refer to the Nebius AI Studio documentation for the most current list of supported models.
- gotcha Rate Limiting and Context Length: Like most LLM providers, Nebius AI Studio may impose rate limits and have maximum context window sizes for its models. Hitting these limits can lead to errors.
Install
-
pip install langchain-nebius
Imports
- ChatNebius
from langchain_nebius import ChatNebius
- NebiusEmbeddings
from langchain_nebius import NebiusEmbeddings
- NebiusRetriever
from langchain_nebius import NebiusRetriever
- NebiusRetrievalTool
from langchain_nebius import NebiusRetrievalTool
Quickstart
import os
from langchain_nebius import ChatNebius
from langchain_core.messages import HumanMessage
# Set your Nebius API key as an environment variable
# os.environ["NEBIUS_API_KEY"] = "your_nebius_api_key"
chat = ChatNebius(
api_key=os.environ.get('NEBIUS_API_KEY', ''),
model="Qwen/Qwen3-14B", # Choose an available model from Nebius AI Studio
temperature=0.6
)
response = chat.invoke([
HumanMessage(content="What is 1 + 1?")
])
print(response.content)