LiteLLM is a model I/O library to standardize API calls to Azure, Anthropic, OpenAI, etc. Hereโ€™s how you can log your LLM API calls to Helicone from LiteLLM using callbacks.

Note: Custom Properties are available in metadata starting with LiteLLM version 1.41.23.

1 line integration

Add HELICONE_API_KEY to your environment variables.

export HELICONE_API_KEY=sk-<your-api-key>
# You can also set it in your code (See below)

Tell LiteLLM you want to log your data to Helicone

litellm.success_callback=["helicone"]

Complete code

from litellm import completion
import os

## set env variables
os.environ["HELICONE_API_KEY"] = "your-helicone-key"
os.environ["OPENAI_API_KEY"], os.environ["COHERE_API_KEY"] = "", ""

# set callbacks
litellm.success_callback=["helicone"]

#openai call
response = completion(
  model="gpt-3.5-turbo",
  messages=[{"role": "user", "content": "Hi ๐Ÿ‘‹ - i'm openai"}],
  metadata={
    "Helicone-Property-Hello": "World"
  }
)

#cohere call
response = completion(
  model="command-r",
  messages=[{"role": "user", "content": "Hi ๐Ÿ‘‹ - i'm cohere"}],
  metadata={
    "Helicone-Property-Hello": "World"
  }
)

print(response)

Feel free to check it out and tell us what you think ๐Ÿ‘‹

For proxy-based integration with LiteLLM, see our LiteLLM Proxy Integration guide.