Trace CometAPI chat completions

Trace CometAPI chat completions made with the OpenAI Python client in Future AGI using traceAI-openai.

Trace your CometAPI chat completions in Future AGI using the OpenAI Python client and traceAI-openai. This guide covers /v1/chat/completions; Responses, image, video and audio routes are outside its scope. There is no traceai-cometapi package.

Install

Use Python 3.10 to 3.13 for traceAI-openai 0.1.10. Install the versions used by the companion example:

pip install traceAI-openai==0.1.10 fi-instrumentation-otel==1.1.0 openai==3.31.0

Trace a chat completion

Set your CometAPI key for the model client and your Future AGI keys for tracing. For self-hosted Future AGI, also set FI_BASE_URL to your collector URL.

export COMETAPI_KEY="YOUR_COMETAPI_KEY"
export FI_API_KEY="YOUR_API_KEY"
export FI_SECRET_KEY="YOUR_SECRET_KEY"

Register and instrument before creating the client. Replace your-model-id with a chat model from CometAPI’s Models page.

import os

from fi_instrumentation import register
from fi_instrumentation.fi_types import ProjectType
from openai import OpenAI
from traceai_openai import OpenAIInstrumentor

trace_provider = register(
    project_type=ProjectType.OBSERVE,
    project_name="my-chatbot",
)
OpenAIInstrumentor().instrument(tracer_provider=trace_provider)

client = OpenAI(
    api_key=os.environ["COMETAPI_KEY"],
    base_url="https://api.cometapi.com/v1",
)

try:
    response = client.chat.completions.create(
        model="your-model-id",
        messages=[{"role": "user", "content": "What is the capital of France?"}],
    )
    print(response.choices[0].message.content)
finally:
    trace_provider.force_flush()
    trace_provider.shutdown()

Save the script and run it. Open Observe and select my-chatbot to find the LLM span. The span’s provider label is openai, not CometAPI. For streaming usage, pass stream_options={"include_usage": True}. Tool execution needs its own span if you want to trace it.

Privacy

By default, traceAI-openai captures prompts, completions, tool arguments and results, and request parameters. To hide these in Future AGI, set the following before starting your process:

export FI_HIDE_INPUTS=true
export FI_HIDE_OUTPUTS=true
export FI_HIDE_LLM_INVOCATION_PARAMETERS=true

With the pinned versions, these settings do not hide tool definitions, session IDs or error messages. Error status and exception events can include the provider’s error body, request ID and local stack paths; do not rely on these switches to hide sensitive error text. CometAPI still receives the content sent to its API.

Troubleshooting

  • 401 from CometAPI: check COMETAPI_KEY.
  • 404, redirect or HTML response: use https://api.cometapi.com/v1 as the base URL; the chat request goes to https://api.cometapi.com/v1/chat/completions.
  • Model call fails: check the model’s API requirements. Some models require /v1/responses, which this guide does not cover.
  • No traces: check the Future AGI keys, FI_BASE_URL if self-hosted, and that instrumentation runs before client creation. See No traces appearing.
  • Streaming span has no token counts: pass stream_options={"include_usage": True}.
  • Python 3.14 installation fails: traceAI-openai 0.1.10 requires Python 3.10 to 3.13.

On traceAI-openai 0.1.10, the model is absent from streaming and failed-call spans, and the CometAPI host is not recorded on the span.

Was this page helpful?

Questions & Discussion