Observability for Helicone with Opik

Helicone is an open-source LLM observability platform that provides monitoring, logging, and analytics for LLM applications. It acts as a proxy layer between your application and LLM providers, offering features like request logging, caching, rate limiting, and cost tracking.

Gateway Overview

Helicone provides a comprehensive observability layer for LLM applications with features including:

  • Unified API: OpenAI-compatible API with access to 100+ models through Helicone’s model registry
  • Intelligent Routing: Automatic failures and fallbacks across providers to ensure reliability
  • No Rate Limits: Skip provider tier restrictions with zero markup on credits
  • Request Logging: Automatic logging of all LLM requests and responses
  • Caching: Reduce costs and improve latency with semantic caching
  • Cost Tracking: Monitor spending across different models and providers with unified observability
  • Multi-Provider Support: Works with OpenAI, Anthropic, Azure OpenAI, and more

Account Setup

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.

Getting Started

Installation

First, ensure you have both opik and openai packages installed:

$pip install opik openai

Configuring Opik

Configure the Opik Python SDK for your deployment type. See the Python SDK Configuration guide for detailed instructions on:

  • CLI configuration: opik configure
  • Code configuration: opik.configure()
  • Self-hosted vs Cloud vs Enterprise setup
  • Configuration files and environment variables

Configuring Helicone

You’ll need a Helicone API key. You can get one by signing up at Helicone.

Set your API key as an environment variable:

$export HELICONE_API_KEY="YOUR_HELICONE_API_KEY"

Or set it programmatically:

1import os
2import getpass
3
4if "HELICONE_API_KEY" not in os.environ:
5 os.environ["HELICONE_API_KEY"] = getpass.getpass("Enter your Helicone API key: ")

Logging LLM Calls

Since Helicone provides an OpenAI-compatible proxy, we can use the Opik OpenAI SDK wrapper to automatically log Helicone calls as generations in Opik.

Simple LLM Call

1import os
2from opik.integrations.openai import track_openai
3from openai import OpenAI
4
5# Create an OpenAI client with Helicone's base URL
6client = OpenAI(
7 api_key=os.environ["HELICONE_API_KEY"],
8 base_url="https://ai-gateway.helicone.ai"
9)
10
11# Wrap the client with Opik tracking
12client = track_openai(client, project_name="helicone-integration-demo")
13
14# Make a chat completion request
15response = client.chat.completions.create(
16 model="gpt-3.5-turbo",
17 messages=[
18 {"role": "system", "content": "You are a knowledgeable AI assistant."},
19 {"role": "user", "content": "What is the largest city in France?"}
20 ]
21)
22
23# Print the assistant's reply
24print(response.choices[0].message.content)

Advanced Usage

Using with the @track decorator

If you have multiple steps in your LLM pipeline, you can use the @track decorator to log the traces for each step. If Helicone is called within one of these steps, the LLM call will be associated with that corresponding step:

1import os
2from opik import track
3from opik.integrations.openai import track_openai
4from openai import OpenAI
5
6# Create and wrap the OpenAI client with Helicone's base URL
7client = OpenAI(
8 api_key=os.environ["HELICONE_API_KEY"],
9 base_url="https://ai-gateway.helicone.ai"
10)
11client = track_openai(client)
12
13@track
14def generate_response(prompt: str):
15 response = client.chat.completions.create(
16 model="gpt-3.5-turbo",
17 messages=[
18 {"role": "system", "content": "You are a knowledgeable AI assistant."},
19 {"role": "user", "content": prompt}
20 ]
21 )
22 return response.choices[0].message.content
23
24@track
25def refine_response(initial_response: str):
26 response = client.chat.completions.create(
27 model="gpt-4",
28 messages=[
29 {"role": "system", "content": "You enhance and polish text responses."},
30 {"role": "user", "content": f"Please improve this response: {initial_response}"}
31 ]
32 )
33 return response.choices[0].message.content
34
35@track(project_name="helicone-integration-demo")
36def generate_and_refine(prompt: str):
37 # First LLM call: Generate initial response
38 initial = generate_response(prompt)
39
40 # Second LLM call: Refine the response
41 refined = refine_response(initial)
42
43 return refined
44
45# Example usage
46result = generate_and_refine("Explain quantum computing in simple terms.")

The trace will show nested LLM calls with hierarchical spans.

Further Improvements

If you have suggestions for improving the Helicone integration, please let us know by opening an issue on GitHub.