Switch language

LangChain

Integrate Bitdeer AI with the LangChain framework for building LLM applications.

LangChain's OpenAI-flavored integrations accept a custom base URL. Point ChatOpenAI at Bitdeer AI to use chains, agents, RAG, and other features with Bitdeer models.

Installation

pip install langchain-openai

Basic usage

from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    base_url="https://api-inference.bitdeer.ai/v1",
    api_key="YOUR_API_KEY",
    model="deepseek-ai/DeepSeek-V4-Pro",
    max_tokens=256,
)

response = llm.invoke("Explain what RAG is in 3 sentences.")
print(response.content)

Vision (multimodal)

from langchain_core.messages import HumanMessage

response = llm.invoke(
    [
        HumanMessage(
            content=[
                {"type": "image_url", "image_url": {"url": "https://example.com/photo.jpg"}},
                {"type": "text", "text": "Describe this image."},
            ]
        )
    ],
    model="moonshotai/Kimi-K2.6",
)
print(response.content)

Streaming

for chunk in llm.stream("Write a haiku about AI."):
    print(chunk.content, end="", flush=True)

Building chains

from langchain_core.prompts import ChatPromptTemplate

prompt = ChatPromptTemplate.from_messages([
    ("system", "You are a helpful coding assistant."),
    ("user", "{input}"),
])

chain = prompt | llm
response = chain.invoke({"input": "Write a Python function to compute Fibonacci numbers."})
print(response.content)

Last updated on

On this page

LangChain · Bitdeer AI