Introducing Virtual MCP Servers
LogoLogo
GithubJoin SlackSignupBook a Demo
  • Documentation
  • Self Hosted
  • Integrations
  • Guides
  • Enterprise
  • Examples
  • OpenAI
  • Vercel AI SDK
  • DeepSeek
  • Anthropic
  • LangChain
  • CrewAI
  • Gemini
  • Bedrock
  • xAI
  • TogetherAI
  • FireworksAI
  • DeepInfra
  • OpenRouter
  • Smithery
  • LlamaIndex
  • Supabase
  • Mem0
Powered by GitBook
LogoLogo

Social

  • LinkedIn
  • X
  • Youtube
  • Github

Platform

  • Pricing
  • Documentation
  • Blog

Company

  • Home
  • About

Legal

  • Privacy Policy
  • Terms of Service

2025 LangDB. All rights reserved.

On this page

Was this helpful?

Export as PDF

OpenAI

Connect LangDB seamlessly using the OpenAI Client SDK for Python, Node.js, or cURL with minimal code changes.

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
    }'
PreviousExamplesNextVercel AI SDK

Was this helpful?