apps/opik-documentation/documentation/templates/integration_template_code.md
INTEGRATION_NAME is [INTEGRATION_DESCRIPTION].
This guide explains how to integrate Opik with [INTEGRATION_NAME] using the [INTEGRATION_NAME] integration provided by Opik. By using the [INTEGRATION_NAME] integration provided by Opik, you can easily track and evaluate your [INTEGRATION_NAME] API calls within your Opik projects as Opik will automatically log the input prompt, model used, token usage, and response generated.
Comet provides a hosted version of the Opik platform, simply create an account and grab your API Key.
You can also run the Opik platform locally, see the installation guide for more information.
Install the required packages:
pip install opik [integration_package]
Configure the Opik Python SDK for your deployment type. See the Python SDK Configuration guide for detailed instructions on:
opik configureopik.configure()In order to configure [INTEGRATION_NAME], you will need to have your [INTEGRATION_NAME] API Key. You can find or create your [INTEGRATION_NAME] API Key in this page.
You can set it as an environment variable:
export [INTEGRATION_API_KEY_NAME]="YOUR_API_KEY"
Or set it programmatically:
import os
import getpass
if "[INTEGRATION_API_KEY_NAME]" not in os.environ:
os.environ["[INTEGRATION_API_KEY_NAME]"] = getpass.getpass("Enter your [INTEGRATION_NAME] API key: ")
# Set project name for organization
os.environ["OPIK_PROJECT_NAME"] = "[integration_name]-integration-demo"
Set up [INTEGRATION_NAME] with Opik tracking:
from opik.integrations.[integration_module] import track_[integration_name]
from [package] import [ClientClass]
# Initialize the [INTEGRATION_NAME] client
client = [ClientClass]()
tracked_client = track_[integration_name](client)
# Set project name for organization
os.environ["OPIK_PROJECT_NAME"] = "[integration_name]-integration-demo"
# Make API calls
response = tracked_client.some_method()
Use the @track decorator to create comprehensive traces:
from opik import track
from opik.integrations.[integration_module] import track_[integration_name]
from [package] import [ClientClass]
client = [ClientClass]()
tracked_client = track_[integration_name](client)
@track
def my_function(input_data):
"""Process data using [INTEGRATION_NAME]."""
response = tracked_client.some_method(input_data)
return response
# Call the tracked function
result = my_function("example input")
[DESCRIBE_SPECIFIC_FEATURES_OF_THE_INTEGRATION]
Once your [INTEGRATION_NAME] calls are logged with Opik, you can view them in the Opik UI. Each API call will create a trace with detailed information including:
Once your [INTEGRATION_NAME] calls are logged with Opik, you can evaluate your LLM application using Opik's evaluation framework:
from opik.evaluation import evaluate
from opik.evaluation.metrics import Hallucination
# Define your evaluation task
def evaluation_task(x):
return {
"message": x["message"],
"output": x["output"],
"reference": x["reference"]
}
# Create the Hallucination metric
hallucination_metric = Hallucination()
# Run the evaluation
evaluation_results = evaluate(
experiment_name="[integration_name]-evaluation",
dataset=your_dataset,
task=evaluation_task,
scoring_metrics=[hallucination_metric],
)
Make sure to set the following environment variables:
# [INTEGRATION_NAME] Configuration
export [INTEGRATION_API_KEY_NAME]="your-[integration-name]-api-key"
# Opik Configuration
export OPIK_PROJECT_NAME="your-project-name"
export OPIK_WORKSPACE="your-workspace-name"
Once you have [INTEGRATION_NAME] integrated with Opik, you can:
Replace these placeholders in templates:
Code Integrations:
[INTEGRATION_NAME] → Actual integration name (e.g., "OpenAI")[integration_name] → Lowercase version (e.g., "openai")[integration_module] → Python module name (e.g., "openai")[integration_package] → Package to install (e.g., "openai")[ClientClass] → Main client class (e.g., "OpenAI")[INTEGRATION_API_KEY_NAME] → Environment variable name (e.g., "OPENAI_API_KEY")[INTEGRATION_API_KEY_URL] → URL where users can create/manage API keys[INTEGRATION_WEBSITE_URL] → Main website URL for the integration[INTEGRATION_DESCRIPTION] → Brief description of what the integration does