Anthropic
Access Anthropic models through LangDB’s API using OpenAI SDK
LangDB provides first class support for Anthropic models.
You can use OpenAI SDK to run the Anthropic models.
# 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)
Was this helpful?