OpenAI

LangDB seamlessly integrate with OpenAI Client.

1

Install OpenAI Client SDK

pip 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
)

Last updated

Was this helpful?