Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Connect LangDB seamlessly using the OpenAI Client SDK for Python, Node.js, or cURL with minimal code changes.
LangDB seamlessly integrate with OpenAI Client.
Install OpenAI Client SDK
pip install openai
npm install openai
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
}'
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
Connect LangDB to your Vercel AI projects using simple setup and start generating text with powerful LLM models instantl
LangDB integrates with applications built Vercel AI SDK.
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);
}
Connect LangDB to LangChain using OpenAI-compatible setup to enhance LLM workflows with full tracing and streamlined monitoring.
Integrate Smithery's EXA MCP server into LangDB to enhance AI workflows with real-time, tool-driven interactions via WebSocket.
LangDB supports MCP servers provided by .
This particular example is for .
Access OpenRouter models through LangDB’s API using OpenAI SDK
LangDB provides first class support for OpenRouter models.
You can use to run the xAI models.
Access Anthropic models through LangDB’s API using OpenAI SDK
LangDB provides first class support for Anthropic models.
You can use to run the Anthropic models.
Connect LangDB to CrewAI using OpenAI-compatible setup to enhance LLM workflows with full tracing and streamlined monitoring.
Access Gemini models through LangDB’s API using OpenAI SDK
LangDB provides first class support for Gemini models.
You can use to run the Gemini models.
Access xAI models through LangDB’s API using OpenAI SDK
LangDB provides first class support for xAI models.
You can use to run the xAI models.
Access Amazon Bedrock models through LangDB’s API using OpenAI SDK
LangDB provides first class support for Bedrock models.
You can use to run the Bedrock models.
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
pip install llama-index openai
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
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)
pip install mem0ai python-dotenv
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)
pip install crewai
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
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."
}
],
}'
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": "claude-3-5-sonnet-20240620",
"messages": [
{
"role": "system",
"content": "You are helpful assistant",
},
{
"role": "user",
"content": "Write a haiku about recursion in programming."
}
]
}'
# 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": "gemini/gemini-1.5-flash-8b",
"messages": [
{
"role": "system",
"content": "You are helpful assistant",
},
{
"role": "user",
"content": "Write a haiku about recursion in programming."
}
]
}'
# 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": "xai/grok-2",
"messages": [
{
"role": "user",
"content": "Write a haiku about recursion in programming."
}
],
}'
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": "bedrock/command-r-v1:0",
"messages": [
{
"role": "user",
"content": "Write a haiku about recursion in programming."
}
],
}'
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
Access TogetherAI models through LangDB’s API using OpenAI SDK
LangDB provides first class support for TogetherAI opensource hosted models.
You can use OpenAI SDK to run the 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="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."
}
],
}'
Access FireworksAI models through LangDB’s API using OpenAI SDK
LangDB provides first class support for FireworksAI opensource hosted models.
You can use OpenAI SDK to run the 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="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."
}
],
}'
Access DeepInfra models through LangDB’s API using OpenAI SDK
LangDB provides first class support for DeepInfra opensource hosted models.
You can use OpenAI SDK to run the 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="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."
}
],
}'
Access DeepSeek models through LangDB’s API using OpenAI SDK, enabling fast, reliable AI performance across platforms.
LangDB provides first class support for DeepSeek AI’s models.
You can use to run the deepseek models.
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."
}
]
}'
# 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();
Connect LangDB to LangChain using OpenAI-compatible setup to generate embeddings and store them in Supabase for efficient data retrieval.
LangDB integrates AI models like OpenAI to generate embeddings and store them in Supabase for efficient data retrieval.
Go to Supabase and create a new project.
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