This directory contains examples of how to use the Helicone Python SDK to log tool usage in your LLM applications.
-
Install the required package:
pip install helicone-helpers
-
Set your Helicone API key as an environment variable (optional):
export HELICONE_API_KEY="your-helicone-api-key"
The simple_example.py file contains a basic calculator tool example that demonstrates the core functionality of logging tool usage with Helicone.
python simple_example.pyThe example.py file contains more complex examples including:
- Weather API tool (with mock data)
- Database query tool (simulated)
- Document search tool (simulated)
python example.py- HeliconeManualLogger: The main class for logging tool usage
- Request Object: Must include
_type: "tool",toolName, andinput - Operation Function: The function that performs the tool operation and logs results
- Result Recorder: Used to append results to be logged to Helicone
# Initialize the logger
helicone_logger = HeliconeManualLogger(api_key="your-api-key")
# Define the operation function
def tool_operation(result_recorder):
# Access input from result_recorder.request
# Perform the operation
# Log results with result_recorder.append_results()
return result
# Log the request
result = helicone_logger.log_request(
request={
"_type": "tool",
"toolName": "your-tool-name",
"input": { ... }
},
operation=tool_operation
)- Session Management: Use
Helicone-Property-Session-Idin additional headers - User Tracking: Use
Helicone-Property-User-Idin additional headers - Custom Properties: Add any custom properties with
Helicone-Property-*headers
For more information, see the Helicone Tools Python SDK documentation.