Working with API

LangDB provides access to 250+ LLMs with OpenAI compatible APIs.

You can use LangDB as a drop-in replacement for OpenAI APIs, making it easy to integrate into existing workflows and libraries such as OpenAI Client SDK.

You can choose from any of the supported models.

from openai import OpenAI

langdb_project_id = "xxxxx"  # LangDB Project ID

client = OpenAI(
    base_url=f"https://api.us-east-1.langdb.ai/{langdb_project_id}/v1",
    api_key="xxxxx" ,           # LangDB token
)
response = client.chat.completions.create(
    model="gpt-4o", # Change Model
    messages=[
        {"role": "system", "content": "You are a helpful assistant"},
        {"role": "user", "content": "What are the earnings of Apple in 2022?"},
    ],
)
print("Assistant:", response.choices[0].message)

Check out the API reference here.

Last updated

Was this helpful?