Trace Novita AI chat completions
Trace Novita AI chat completions made with the OpenAI Python client in Future AGI using traceAI-openai.
Trace Novita AI chat completions in Future AGI using the OpenAI Python client and traceAI-openai. This guide covers the OpenAI-compatible chat endpoint, not Novita’s other APIs or SDKs.
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.35.1
Trace a chat completion
Set your Novita API 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 NOVITA_API_KEY="YOUR_NOVITA_API_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 an ID from Novita’s Model Hub. Keep max_tokens in the request as shown in Novita’s chat reference.
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["NOVITA_API_KEY"],
base_url="https://api.novita.ai/openai/v1",
)
try:
response = client.chat.completions.create(
model="your-model-id",
messages=[{"role": "user", "content": "What is the capital of France?"}],
max_tokens=128,
)
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 Novita. For tool calls, choose a model with function calling; instrument the tool separately if you need a span for its execution.
Which base URL
Use https://api.novita.ai/openai/v1, which matches the chat endpoint in Novita’s Quickstart. The OpenAI client appends /chat/completions. Novita also documents https://api.novita.ai/openai in some examples; avoid adding /v1 twice.
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 and local stack paths; do not rely on these switches to hide sensitive error text. Novita still receives the content sent to its API.
Troubleshooting
- 401 or 403 from Novita: check your API key and model access. See Novita error codes.
- 404 model not found: check the model ID in the Model Hub or the models endpoint.
- 404 page not found: check the base URL and remove a duplicated
/v1. - Function calling not supported: choose a model whose features include
function-calling. - No traces: check the Future AGI keys,
FI_BASE_URLif 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 Novita host is not recorded on the span. Use Novita’s billing for spend.
Questions & Discussion