Only this pageAll pages
Powered by GitBook
1 of 18

Integrations

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

OpenAI

LangDB seamlessly integrate with OpenAI Client.

1

Install OpenAI Client SDK

pip install openai
npm install openai
2

Add LangDB to your code

from openai import OpenAI
client = OpenAI(
    base_url="https://api.us-east-1.langdb.ai"  # LangDB API base URL,
    api_key=api_key,  # Replace with your LangDB token
)
# Make the API call to LangDB's Completions API
response = client.chat.completions.create(
    model="gpt-4o",  # Use the model
    messages=[{"role": "system", "content": "You are a helpful assistant."},
              {"role": "user", "content": "Hello!"}],  
    extra_headers={"x-project-id": "xxxxx"} # LangDB Project ID
)
import { OpenAI } from 'openai'; // Assuming you're using the OpenAI Node.js SDK
const apiBase = "https://api.us-east-1.langdb.ai";  // LangDB API base URL
const apiKey = "LANGDB_API_KEY";  // Replace with your LangDB token
const defaultHeaders = { "x-project-id": "xxxx" };  // LangDB Project ID
const client = new OpenAI({
  baseURL: apiBase,
  apiKey: apiKey,
});
const response = await client.chat.completions.create({
      model: "gpt-4o-mini",  // Use the model
      messages: [{"role": "user","content": "Hello?"}], 
    }, { headers: defaultHeaders });
// Rest of Your Code
curl "https://api.us-east-1.langdb.ai/v1/chat/completions" \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $LANGDB_API_KEY" \
    -X "X-Project-Id: $Project_ID" \
    -d '{
        "model": "gpt-4o",
        "messages": [
            {
                "role": "user",
                "content": "Write a haiku about recursion in programming."
            }
        ],
        "temperature": 0.8
    }'

LangChain

LangDB integrates seamlessly with popular libraries like LangChain, providing tracing support to capture detailed logs for workflows. Below is a complete example of using LangChain with LangDB.

1

Install LangChain

2

Add LangDB to your Code

Examples

Frameworks

Check out full examples in the .

pip install langchain langchain-openai
from langchain_openai import ChatOpenAI

api_base = "https://api.us-east-1.langdb.ai"
api_key = "xxxx" # LangDB API Key
default_headers = {
    "x-project-id": "xxxxx",  ### LangDB Project ID
}
llm = ChatOpenAI(
    model_name='gpt-4o' , 
    temperature=0.3, 
    openai_api_base=api_base, 
    default_headers=default_headers,
    disable_streaming=True )

# Your LangChain Code here
samples

Vercel AI SDK

LangDB integrates with applications built Vercel AI SDK.

1

Install Vercel AI SDK

npm i ai
npm i @langdb/vercel-provider
2

Add LangDB to your Code

import { generateText } from 'ai';
import { createLangDB } from '@langdb/vercel-provider';

const langdb = createLangDB({
  apiKey: process.env.LANGDB_API_KEY,
  projectId: 'your-project-id',
});

export async function generateTextExample() {
  const { text } = await generateText({
    model: langdb('openai/gpt-4o-mini'),
    prompt: 'Write a Python function that sorts a list:',
  });

  console.log(text);
}

Gemini

LangDB provides first class support for Gemini models.

# Please install OpenAI SDK first: `pip3 install openai`
from openai import OpenAI
api_base = "https://api.us-east-1.langdb.ai"  # LangDB API base URL
api_key = "xxxxx"  # Replace with your LangDB token
default_headers = {"x-project-id": "xxxxx"} # LangDB Project ID
client = OpenAI(
    base_url=api_base,
    api_key=api_key,
)
response = client.chat.completions.create(
    model="gemini/gemini-1.5-flash-8b",
    messages=[
        {"role": "system", "content": "You are a helpful assistant"},
        {"role": "user", "content": "Hello"}
    ],
    stream=False
)
print(response.choices[0].message.content)
// Please install OpenAI SDK first: `npm install openai`
import OpenAI from "openai";
const apiBase = "https://api.us-east-1.langdb.ai";  // LangDB API base URL
const apiKey = "LANGDB_API_KEY";  // Replace with your LangDB token
const defaultHeaders = { "x-project-id": "xxxx" };  // LangDB Project ID
const client = new OpenAI({
  baseURL: apiBase,
  apiKey: apiKey,
});
async function main() {
  const completion = await client.chat.completions.create({
    messages: [{ role: "system", content: "You are a helpful assistant." }, {"role": "user", "content": "Hello"}],
    model: "gemini/gemini-1.5-flash-8b",
  }, { headers: defaultHeaders });
  console.log(completion.choices[0].message.content);
}
main();
curl "https://api.us-east-1.langdb.ai/v1/chat/completions" \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $LANGDB_API_KEY" \
    -X "X-Project-Id: $Project_ID" \
    -d '{
        "model": "gemini/gemini-1.5-flash-8b",
        "messages": [
            {
                "role": "system",
                "content": "You are helpful assistant",
            },
            {
                "role": "user",
                "content": "Write a haiku about recursion in programming."
            }
        ]
    }'

You can use to run the Gemini models.

OpenAI SDK

OpenAI

Integration with OpenAI SDK

DeepSeek

Support for DeepSeek Models

Anthropic

Support for Anthropic Models

Gemini

Support for Gemini Models

Bedrock

Support for Bedrock Models

xAI

Support for xAI Models

TogetherAI

Support for TogetherAI Models

FireworksAI

Support for FireworksAI Models

DeepInfra

Support for DeepInfra Models

OpenRouter

Support for OpenRouter Models

Smithery

Support for MCP servers on smithery.ai

Vercel AI

Integration with Vercel AI SDK

LangChain

Integration with LangChain

CrewAI

Integration with CrewAI

LlamaIndex

Integration with LlamaIndex

Supabase

Integration with Supabase

mem0

Integration with Mem0

Anthropic

LangDB provides first class support for Anthropic models.

# Please install OpenAI SDK first: `pip3 install openai`
from openai import OpenAI
api_base = "https://api.us-east-1.langdb.ai"  # LangDB API base URL
api_key = "xxxxx"  # Replace with your LangDB token
default_headers = {"x-project-id": "xxxxx"} # LangDB Project ID
client = OpenAI(
    base_url=api_base,
    api_key=api_key,
)
response = client.chat.completions.create(
    model="claude-3-5-sonnet-20240620",
    messages=[
        {"role": "system", "content": "You are a helpful assistant"},
        {"role": "user", "content": "Hello"}
    ],
    stream=False
)
print(response.choices[0].message.content)
// Please install OpenAI SDK first: `npm install openai`
import OpenAI from "openai";
const apiBase = "https://api.us-east-1.langdb.ai";  // LangDB API base URL
const apiKey = "LANGDB_API_KEY";  // Replace with your LangDB token
const defaultHeaders = { "x-project-id": "xxxx" };  // LangDB Project ID
const client = new OpenAI({
  baseURL: apiBase,
  apiKey: apiKey,
});
async function main() {
  const completion = await client.chat.completions.create({
    messages: [{ role: "system", content: "You are a helpful assistant." }, {"role": "user", "content": "Hello"}],
    model: "claude-3-5-sonnet-20240620",
  }, { headers: defaultHeaders });
  console.log(completion.choices[0].message.content);
}
main();
curl "https://api.us-east-1.langdb.ai/v1/chat/completions" \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $LANGDB_API_KEY" \
    -X "X-Project-Id: $Project_ID" \
    -d '{
        "model": "claude-3-5-sonnet-20240620",
        "messages": [
            {
                "role": "system",
                "content": "You are helpful assistant",
            },
            {
                "role": "user",
                "content": "Write a haiku about recursion in programming."
            }
        ]
    }'

CrewAI

LangDB integrates seamlessly with popular libraries like CrewAI, providing tracing support to capture detailed logs for workflows. Below is a complete example of using CrewAI with LangDB.

1

Install CrewAI

pip install crewai
2

Add LangDB to your Code

from crewai import LLM
project_id = "xxxx" ## LangDB Project ID
default_headers = {"x-project-id": project_id}
os.environ["OPENAI_API_KEY"] = (
    "xxxx"  ## LangDB API Key
)
llm_writer = LLM(model="gpt-4o-mini", 
                 base_url=api_base, 
                 extra_headers=default_headers)

# Your CrewAi code here

DeepSeek

LangDB provides first class support for DeepSeek AI’s models.

# Please install OpenAI SDK first: `pip3 install openai`
from openai import OpenAI
api_base = "https://api.us-east-1.langdb.ai"  # LangDB API base URL
api_key = "xxxxx"  # Replace with your LangDB token
default_headers = {"x-project-id": "xxxxx"} # LangDB Project ID
client = OpenAI(
    base_url=api_base,
    api_key=api_key,
)
response = client.chat.completions.create(
    model="deepseek-reasoner",
    messages=[
        {"role": "system", "content": "You are a helpful assistant"},
        {"role": "user", "content": "Hello"}
    ],
    stream=False
)
print(response.choices[0].message.content)
// Please install OpenAI SDK first: `npm install openai`
import OpenAI from "openai";
const apiBase = "https://api.us-east-1.langdb.ai";  // LangDB API base URL
const apiKey = "LANGDB_API_KEY";  // Replace with your LangDB token
const defaultHeaders = { "x-project-id": "xxxx" };  // LangDB Project ID
const client = new OpenAI({
  baseURL: apiBase,
  apiKey: apiKey,
});
async function main() {
  const completion = await client.chat.completions.create({
    messages: [{ role: "system", content: "You are a helpful assistant." }, {"role": "user", "content": "Hello"}],
    model: "deepseek-reasoner",
  }, { headers: defaultHeaders });
  console.log(completion.choices[0].message.content);
}
main();
curl "https://api.us-east-1.langdb.ai/v1/chat/completions" \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $LANGDB_API_KEY" \
    -X "X-Project-Id: $Project_ID" \
    -d '{
        "model": "deepseek-reasoner",
        "messages": [
            {
                "role": "user",
                "content": "Write a haiku about recursion in programming."
            }
        ]
    }'

Cover

You can use to run the Anthropic models.

Check out full examples .

You can use to run the deepseek models.

OpenAI SDK
here
OpenAI SDK

Bedrock

LangDB provides first class support for Bedrock models.

from openai import OpenAI
client = OpenAI(
    base_url="https://api.us-east-1.langdb.ai"  # LangDB API base URL,
    api_key=api_key,  # Replace with your LangDB token
)
# Make the API call to LangDB's Completions API
response = client.chat.completions.create(
    model="bedrock/command-r-v1:0",  # Use the model
    messages=[{"role": "system", "content": "You are a helpful assistant."},
              {"role": "user", "content": "Hello!"}],  
    extra_headers={"x-project-id": "xxxxx"} # LangDB Project ID
)
import { OpenAI } from 'openai'; // Assuming you're using the OpenAI Node.js SDK
const apiBase = "https://api.us-east-1.langdb.ai";  // LangDB API base URL
const apiKey = "LANGDB_API_KEY";  // Replace with your LangDB token
const defaultHeaders = { "x-project-id": "xxxx" };  // LangDB Project ID
const client = new OpenAI({
  baseURL: apiBase,
  apiKey: apiKey,
});
const response = await client.chat.completions.create({
      model: "bedrock/command-r-v1:0",  // Use the model
      messages: [{"role": "user","content": "What are the earnings of Apple in 2022?"}], 
    }, { headers: defaultHeaders });
// Rest of Your Code
curl "https://api.us-east-1.langdb.ai/v1/chat/completions" \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $LANGDB_API_KEY" \
    -X "X-Project-Id: $Project_ID" \
    -d '{
        "model": "bedrock/command-r-v1:0",
        "messages": [
            {
                "role": "user",
                "content": "Write a haiku about recursion in programming."
            }
        ],
    }'

You can use to run the Bedrock models.

OpenAI SDK

FireworksAI

LangDB provides first class support for FireworksAI opensource hosted models.

from openai import OpenAI
client = OpenAI(
    base_url="https://api.us-east-1.langdb.ai"  # LangDB API base URL,
    api_key=api_key,  # Replace with your LangDB token
)
# Make the API call to LangDB's Completions API
response = client.chat.completions.create(
    model="fireworksai/deepseek-r1",  # Use the model
    messages=[{"role": "user", "content": "Hello!"}],  
    extra_headers={"x-project-id": "xxxxx"} # LangDB Project ID
)
import { OpenAI } from 'openai'; // Assuming you're using the OpenAI Node.js SDK
const apiBase = "https://api.us-east-1.langdb.ai";  // LangDB API base URL
const apiKey = "LANGDB_API_KEY";  // Replace with your LangDB token
const defaultHeaders = { "x-project-id": "xxxx" };  // LangDB Project ID
const client = new OpenAI({
  baseURL: apiBase,
  apiKey: apiKey,
});
const response = await client.chat.completions.create({
      model: "fireworksai/deepseek-r1",  // Use the model
      messages: [{"role": "user","content": "What are the earnings of Apple in 2022?"}], 
    }, { headers: defaultHeaders });
// Rest of Your Code\
curl "https://api.us-east-1.langdb.ai/v1/chat/completions" \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $LANGDB_API_KEY" \
    -X "X-Project-Id: $Project_ID" \
    -d '{
        "model": "fireworksai/deepseek-r1",
        "messages": [
            {
                "role": "user",
                "content": "Write a haiku about recursion in programming."
            }
        ],
    }'

You can use to run the xAI models.

OpenAI SDK

DeepInfra

LangDB provides first class support for DeepInfra opensource hosted models.

from openai import OpenAI
client = OpenAI(
    base_url="https://api.us-east-1.langdb.ai"  # LangDB API base URL,
    api_key=api_key,  # Replace with your LangDB token
)
# Make the API call to LangDB's Completions API
response = client.chat.completions.create(
    model="deepinfra/phi-4",  # Use the model
    messages=[{"role": "user", "content": "Hello!"}],  
    extra_headers={"x-project-id": "xxxxx"} # LangDB Project ID
)
import { OpenAI } from 'openai'; // Assuming you're using the OpenAI Node.js SDK
const apiBase = "https://api.us-east-1.langdb.ai";  // LangDB API base URL
const apiKey = "LANGDB_API_KEY";  // Replace with your LangDB token
const defaultHeaders = { "x-project-id": "xxxx" };  // LangDB Project ID
const client = new OpenAI({
  baseURL: apiBase,
  apiKey: apiKey,
});
const response = await client.chat.completions.create({
      model: "deepinfra/phi-4",  // Use the model
      messages: [{"role": "user","content": "What are the earnings of Apple in 2022?"}], 
    }, { headers: defaultHeaders });
// Rest of Your Code\
curl "https://api.us-east-1.langdb.ai/v1/chat/completions" \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $LANGDB_API_KEY" \
    -X "X-Project-Id: $Project_ID" \
    -d '{
        "model": "deepinfra/phi-4",
        "messages": [
            {
                "role": "user",
                "content": "Write a haiku about recursion in programming."
            }
        ],
    }'

You can use to run the xAI models.

OpenAI SDK

TogetherAI

LangDB provides first class support for TogetherAI opensource hosted models.

from openai import OpenAI
client = OpenAI(
    base_url="https://api.us-east-1.langdb.ai"  # LangDB API base URL,
    api_key=api_key,  # Replace with your LangDB token
)
# Make the API call to LangDB's Completions API
response = client.chat.completions.create(
    model="togetherai/DeepSeek-V3",  # Use the model
    messages=[{"role": "user", "content": "Hello!"}],  
    extra_headers={"x-project-id": "xxxxx"} # LangDB Project ID
)
import { OpenAI } from 'openai'; // Assuming you're using the OpenAI Node.js SDK
const apiBase = "https://api.us-east-1.langdb.ai";  // LangDB API base URL
const apiKey = "LANGDB_API_KEY";  // Replace with your LangDB token
const defaultHeaders = { "x-project-id": "xxxx" };  // LangDB Project ID
const client = new OpenAI({
  baseURL: apiBase,
  apiKey: apiKey,
});
const response = await client.chat.completions.create({
      model: "togetherai/DeepSeek-V3",  // Use the model
      messages: [{"role": "user","content": "What are the earnings of Apple in 2022?"}], 
    }, { headers: defaultHeaders });
// Rest of Your Code\
curl "https://api.us-east-1.langdb.ai/v1/chat/completions" \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $LANGDB_API_KEY" \
    -X "X-Project-Id: $Project_ID" \
    -d '{
        "model": "togetherai/DeepSeek-V3",
        "messages": [
            {
                "role": "user",
                "content": "Write a haiku about recursion in programming."
            }
        ],
    }'

You can use to run the xAI models.

OpenAI SDK

xAI

LangDB provides first class support for xAI models.

from openai import OpenAI
client = OpenAI(
    base_url="https://api.us-east-1.langdb.ai"  # LangDB API base URL,
    api_key=api_key,  # Replace with your LangDB token
)
# Make the API call to LangDB's Completions API
response = client.chat.completions.create(
    model="xai/grok-2",  # Use the model
    messages=[{"role": "user", "content": "Hello!"}],  
    extra_headers={"x-project-id": "xxxxx"} # LangDB Project ID
)
import { OpenAI } from 'openai'; // Assuming you're using the OpenAI Node.js SDK
const apiBase = "https://api.us-east-1.langdb.ai";  // LangDB API base URL
const apiKey = "LANGDB_API_KEY";  // Replace with your LangDB token
const defaultHeaders = { "x-project-id": "xxxx" };  // LangDB Project ID
const client = new OpenAI({
  baseURL: apiBase,
  apiKey: apiKey,
});
const response = await client.chat.completions.create({
      model: "xai/grok-2",  // Use the model
      messages: [{"role": "user","content": "What are the earnings of Apple in 2022?"}], 
    }, { headers: defaultHeaders });
// Rest of Your Code\
curl "https://api.us-east-1.langdb.ai/v1/chat/completions" \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $LANGDB_API_KEY" \
    -X "X-Project-Id: $Project_ID" \
    -d '{
        "model": "xai/grok-2",
        "messages": [
            {
                "role": "user",
                "content": "Write a haiku about recursion in programming."
            }
        ],
    }'

You can use to run the xAI models.

OpenAI SDK

Smithery

from openai import OpenAI
from dotenv import load_dotenv
import os
import base64
import json
from urllib.parse import quote
load_dotenv()

def urlEncode(data_dict):
    """Convert dictionary to base64 and then URL encode it"""
    return quote(base64.b64encode(json.dumps(data_dict).encode()).decode())

config = {
    "exaApiKey": os.getenv("EXA_API_KEY")
}

config_str = urlEncode(config)
web_socket_url = "wss://your-mcp-server.com/ws"
extra_body = {
    "mcp_servers": [
        {
            "server_url": f"{web_socket_url}?config={config_str}",
            "type": "ws"
        }
    ]
}
client = OpenAI(
    api_key=os.getenv("LANGDB_API_KEY"),
    base_url=os.getenv("LANGDB_API_URL")

)
response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "what is langdb?"}],
    extra_body = extra_body
)
print(response)

LangDB supports MCP servers provided by .

This particular example is for .

Smithery
EXA MCP server

LlamaIndex

1

Install LlamaIndex

pip install llama-index openai
2

Add LangDB into your Code

import os

from llama_index.llms import openai
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
from llama_index.core import Settings
from llama_index.llms.openai import OpenAI

Settings.llm = OpenAI(
    base_url=os.getenv("OPENAI_API_BASE"),
    api_key=os.getenv("OPENAI_API_KEY"),
    model="gpt-4o-mini"
)

documents = SimpleDirectoryReader("data").load_data()
## Rest of your LlamaIndex

Check out full examples in the .

samples
Cover
Cover
Cover
Cover
Cover

Supabase

LangDB integrates AI models like OpenAI to generate embeddings and store them in Supabase for efficient data retrieval.

Preparing Database

1

Create a Supabase Project

2

Enable PgVector

create extension vector;
3

Create a table to store Embeddings

create table embeddings (
  id bigserial primary key,
  content text,
  embedding vector(1536)
);

Generating and Storing Embeddings

1

Install Libraries

pip install openai python-dotenv supabase
2

Generate Embeddings

from openai import OpenAI
from dotenv import load_dotenv
from supabase import create_client, Client
import os

load_dotenv()
api_key = os.getenv("LANGDB_API_KEY")
project_id = os.getenv("LANGDB_PROJECT_ID")
base_url = f"https://api.us-east-1.langdb.ai/{project_id}/v1"


client = OpenAI(
    base_url=base_url,
    api_key=api_key,
)

text = "Hello LangDB"
response = client.embeddings.create(
    model="text-embedding-ada-002",
    input=text,
)

embedding = response.data[0].embedding
3

Store in Supabase

# # Store in Supabase
result = supabase.table('embeddings').insert({
    "content": text,
    "embedding": embedding
}).execute()

Go to and create a new project.

Supabase
Cover
Cover
Cover
Cover
Cover
Cover
Cover
Cover
Cover
Cover
Cover

Mem0

LangDB seemlessly integrate with Mem0.

1

Install mem0 Client

pip install mem0ai python-dotenv
2

Add LangDB into your code

from mem0 import Memory
from dotenv import load_dotenv
load_dotenv()
import os
langdb_api_key = os.getenv("LANGDB_API_KEY")
langdb_project_id = os.getenv("LANGDB_PROJECT_ID")
base_url =  f"https://api.us-east-1.langdb.ai/{langdb_project_id}/v1"  

config = {
    "llm": {
        "provider": "openai",
        "config": {
            "model": "gpt-4o",
            "temperature": 0.0,
            "api_key": langdb_api_key,
            "openai_base_url": base_url,
        },
    },
    "embedder": {
        "provider": "openai",
        "config": {
            "model": "text-embedding-ada-002",
            "api_key": langdb_api_key,
            "openai_base_url": base_url,
        },
    }
}
m = Memory.from_config(config_dict=config)

result = m.add(
    "I like to take long walks on weekends.",
    user_id="alice",
    metadata={"category": "hobbies"},
)

print(result)

Check out the for more information.

Mem0 documentation

OpenRouter

LangDB provides first class support for OpenRouter models.

from openai import OpenAI
client = OpenAI(
    base_url="https://api.us-east-1.langdb.ai"  # LangDB API base URL,
    api_key=api_key,  # Replace with your LangDB token
)
# Make the API call to LangDB's Completions API
response = client.chat.completions.create(
    model="openrouter/aion-1.0-mini",  # Use the model
    messages=[{"role": "user", "content": "Hello!"}],  
    extra_headers={"x-project-id": "xxxxx"} # LangDB Project ID
)
import { OpenAI } from 'openai'; // Assuming you're using the OpenAI Node.js SDK
const apiBase = "https://api.us-east-1.langdb.ai";  // LangDB API base URL
const apiKey = "LANGDB_API_KEY";  // Replace with your LangDB token
const defaultHeaders = { "x-project-id": "xxxx" };  // LangDB Project ID
const client = new OpenAI({
  baseURL: apiBase,
  apiKey: apiKey,
});
const response = await client.chat.completions.create({
      model: "openrouter/aion-1.0-mini",  // Use the model
      messages: [{"role": "user","content": "What are the earnings of Apple in 2022?"}], 
    }, { headers: defaultHeaders });
// Rest of Your Code\
curl "https://api.us-east-1.langdb.ai/v1/chat/completions" \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $LANGDB_API_KEY" \
    -X "X-Project-Id: $Project_ID" \
    -d '{
        "model": "openrouter/aion-1.0-mini",
        "messages": [
            {
                "role": "user",
                "content": "Write a haiku about recursion in programming."
            }
        ],
    }'

You can use to run the xAI models.

OpenAI SDK