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

TrueFoundry

Trace TrueFoundry AI Gateway 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://gateway.truefoundry.ai/v1", api_key=os.environ["TRUEFOUNDRY_API_KEY"])
response = client.chat.completions.create(
model="<MODEL_NAME>",
messages=[{"role": "user", "content": "What is the capital of France?"}],
)
print(response.choices[0].message.content)
cetra.flush()

Your tenant may serve the gateway on its own host, for example *.truefoundry.cloud.

  • Each chat completion is an llm span with the provider openai: no TrueFoundry host is in cetra’s host table.
  • Input and output token counts come from the response.
  • No built-in price: add a custom model price in Settings → Model prices to get a cost.

The AI Gateway can send its spans to an OTLP endpoint from the dashboard: AI Gateway, Controls, Settings, OTEL Config. Set the traces endpoint (a full URL ending in /v1/traces), the encoding (protobuf over HTTP, or gRPC), an Authorization-style header and any extra resource attributes. The Exclude Request Data toggle removes the content. With ENABLE_GEN_AI_OTEL_ATTRIBUTES=true, the spans carry gen_ai.operation.name, gen_ai.provider.name (the upstream provider), the request and response models, the token counts and the messages, next to TrueFoundry’s own tfy.* attributes.

Setup only: cetra has not verified this export. The cost is reported only under a tfy.* key the docs do not name, which cetra does not read. One partner guide lists legacy token key names (gen_ai.usage.prompt_tokens and completion_tokens) where the docs list the current ones, so the token keys are unverified too.

  • Setup only: no spans of TrueFoundry are captured in the repository.
  • cetra maps no TrueFoundry host to a provider, so the provider stays what your instrumentation records (usually openai) and no built-in price applies. Add a custom model price in Settings → Model prices.
  • The OTLP export above is not verified by cetra; its cost key is not read.
  • Do not instrument both sides: an app with its own OpenTelemetry instrumentation behind a traced gateway counts each call twice, because the gateway joins the app’s trace through traceparent and its span carries the same tokens and cost. Trace the gateway (it covers several apps and languages) or the app, not both. This is not verified for TrueFoundry.
  • With plain OpenInference or the official OpenAI instrumentation in Python, the provider shows as openai: they do not record the endpoint. Use cetra.init(instrument=["openai"]) or OpenLLMetry.
  • If a field is missing, look at the span’s Attributes tab and compare it with Span attributes.