Use this file to discover all available pages before exploring further.
This guide shows how to integrate Novita AI with MLflow Tracing. By using Novita AI’s OpenAI-compatible endpoint (https://api.novita.ai/openai), you can capture prompts, responses, latency, token usage, and model metadata in MLflow.
import openaiimport mlflow# Enable auto-tracing for OpenAI-compatible callsmlflow.openai.autolog()# Optional: set tracking target and experimentmlflow.set_tracking_uri("http://localhost:5000")mlflow.set_experiment("Novita AI")client = openai.OpenAI( base_url="https://api.novita.ai/openai", api_key="<your_novita_api_key>",)response = client.chat.completions.create( model="deepseek/deepseek-r1", messages=[ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "What is the capital of France?"}, ],)print(response.choices[0].message.content)
import jsonfrom openai import OpenAIimport mlflowfrom mlflow.entities import SpanType# Initialize the OpenAI client with Novita AI API endpointclient = OpenAI( base_url="https://api.novita.ai/openai", api_key="<your_novita_api_key>",)# Create a parent span for the Novita AI call@mlflow.trace(span_type=SpanType.CHAIN)def answer_question(question: str): messages = [{"role": "user", "content": question}] response = client.chat.completions.create( model="deepseek/deepseek-r1", messages=messages, ) # Attach session/user metadata to the trace mlflow.update_current_trace( metadata={ "mlflow.trace.session": "session-12345", "mlflow.trace.user": "user-a", } ) return response.choices[0].message.contentanswer = answer_question("What is the capital of France?")