Skip to content
GitHubLog inStart free
cetra is not released yet. These docs describe the development version.

Perplexity

Trace Perplexity model calls with cetra through the OpenAI client.

Terminal window
pip install "cetra-sdk[openai]" openai
import os
import cetra
from openai import OpenAI
cetra.init(instrument=["openai"])
client = OpenAI(base_url="https://api.perplexity.ai", api_key=os.environ["PERPLEXITY_API_KEY"])
response = client.chat.completions.create(
model="sonar",
messages=[{"role": "user", "content": "What is the capital of France?"}],
)
print(response.choices[0].message.content)
cetra.flush()
  • Each chat completion is an llm span with the provider perplexity.
  • Input and output token counts come from the response.
  • Cost comes from the built-in prices.
  • With cetra.init(instrument=["openai"]), the endpoint host is in server.address, and cetra names the provider from it.
  • Search results and citations stay in the raw response; cetra records the messages and token counts.
  • No spans of Perplexity are captured in the repository. cetra maps the host api.perplexity.ai to the provider perplexity.
  • If a field is missing, look at the span’s Attributes tab and compare it with Span attributes.