Working with API

LangDB provides access to 350+ 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="anthropic/claude-sonnet-4", # 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)

After sending your request, you can see the Traces on the dashboard:

Trace after running simple API call

Check out the API reference here.

Last updated

Was this helpful?