A Python SDK for monitoring and analyzing AI API interactions with LLM services
Project description
Coolhand Python
Monitor and log LLM API calls from OpenAI, Anthropic, Google Gemini, GitHub Copilot, Vertex AI, OpenRouter, Cloudflare AI Gateway, and more — including pydantic-ai and Dramatiq — to the Coolhand analytics platform.
Python 3.8 and 3.9 support deprecated: As of v0.4.0, coolhand requires Python 3.10 or later. Python 3.8 reached end-of-life in October 2024 and 3.9 in October 2025. If you are on an older Python version, pin to
coolhand<0.4.0.
Installation
pip install coolhand
Getting Started
- Get API Key: Visit coolhandlabs.com to create a free account
- Install:
pip install coolhand - Configure: Set
COOLHAND_API_KEYandimport coolhandin your app - Deploy: Your AI calls are now automatically monitored!
Quick Start
Automatic Global Monitoring
Set it and forget it! Monitor ALL AI API calls across your entire application with minimal configuration.
import coolhand # Auto-initializes and starts monitoring
# That's it! ALL AI API calls are now automatically monitored:
# ✅ OpenAI SDK calls
# ✅ Anthropic API calls
# ✅ Google Gemini API calls
# ✅ GitHub Copilot SDK calls
# ✅ ANY library making AI API calls via httpx
# Your existing code works unchanged:
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Hello!"}]
)
# The request and response have been automatically logged to Coolhand!
Why Automatic Monitoring:
- Zero refactoring - No code changes to existing services
- Complete coverage - Monitors all AI libraries using httpx automatically
- Security built-in - Automatic credential sanitization
- Performance optimized - Negligible overhead via async logging
- Future-proof - Automatically captures new AI calls added by your team
Configuration
Environment Variables
| Variable | Required | Default | Description |
|---|---|---|---|
COOLHAND_API_KEY |
Yes | - | Your Coolhand API key for authentication |
COOLHAND_BASE_URL |
No | https://coolhandlabs.com |
Override the API host (self-hosted deployments) |
COOLHAND_SILENT |
No | true |
Set to false for verbose logging output |
Manual Configuration
from coolhand import Coolhand
coolhand_client = Coolhand(
api_key='your-api-key',
silent=False, # Enable verbose logging
)
For excluding noisy endpoints (health checks, batch jobs) or pointing the SDK at a self-hosted backend, see Advanced Configuration.
Usage Examples
With OpenAI
import coolhand
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)
# Request automatically logged to Coolhand!
With Anthropic
import coolhand
from anthropic import Anthropic
client = Anthropic()
response = client.messages.create(
model="claude-3-opus-20240229",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.content[0].text)
# Request automatically logged to Coolhand!
With Google Gemini
import coolhand
import google.generativeai as genai
genai.configure(api_key="your-gemini-api-key")
model = genai.GenerativeModel("gemini-pro")
response = model.generate_content("Hello!")
print(response.text)
# Request automatically logged to Coolhand!
With GitHub Copilot SDK
import coolhand
# GitHub Copilot SDK calls are automatically intercepted
# via JsonRpcClient patching — no additional setup needed.
With Streaming
import coolhand
from openai import OpenAI
client = OpenAI()
stream = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Tell me a story"}],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")
# Complete streamed response automatically logged to Coolhand!
What Gets Logged
The monitor captures:
- Request Data: Method, URL, headers, request body
- Response Data: Status code, headers, response body
- Timing: Request timestamp, response timestamp, duration
- LLM-Specific: Model used, token counts, streaming status
Headers containing API keys are automatically sanitized for security.
Supported Libraries
Coolhand works with any library that uses httpx, requests, or the GitHub Copilot SDK:
- OpenAI Python SDK
- Anthropic Python SDK
- Google Gemini (
google-generativeai/google-genai) - Azure AI Inference (
azure-ai-inference) - GitHub Models
- GitHub Copilot SDK
- Vertex AI
- Cloudflare AI Gateway
- OpenRouter
- pydantic-ai
- Any other library using httpx or requests
See Supported Libraries for the full interception mechanism breakdown and streaming details.
How It Works
Importing coolhand patches httpx, requests, and the GitHub Copilot JsonRpcClient at the class level. Requests to LLM APIs are intercepted, credentials are redacted, and data is submitted to Coolhand. Non-LLM requests pass through unchanged.
Integrations
| Integration | Status | Guide |
|---|---|---|
| Dramatiq + pydantic-ai | ✅ Supported | docs/dramatiq.md |
| Celery | 🔜 Coming soon | — |
Feedback Service
Collect user feedback on LLM responses to improve your AI outputs.
Frontend Feedback Widget: For browser-based feedback collection, see coolhand-js.
from coolhand import Coolhand
ch = Coolhand(api_key='your-api-key')
# Submit positive feedback
ch.create_feedback({
'llm_request_log_id': 'abc123def456', # hashid from a prior response; a raw integer FK also still works
'sentiment': 'like',
'explanation': 'Very helpful response!'
})
# Submit negative feedback with a correction
ch.create_feedback({
'original_output': 'The capital of France is London.',
'sentiment': 'dislike',
'revised_output': 'The capital of France is Paris.'
})
For the full field reference, matching strategies, and sentiment values, see Feedback API.
Troubleshooting
Enable Debug Output
from coolhand import Coolhand
Coolhand(
api_key='your-api-key',
silent=False # Enable verbose logging
)
Or via environment variable:
export COOLHAND_SILENT=false
API Key
Sign up for free at coolhandlabs.com to get your API key and start monitoring your LLM usage.
What you get:
- Complete LLM request and response logging
- Usage analytics and insights
- No credit card required to start
Security
- API keys in request headers are automatically redacted
- Sensitive URL query parameters (
key,api_key,token, etc.) are automatically redacted - No sensitive data is exposed in logs
- All data is sent via HTTPS to Coolhand servers
Documentation
- Advanced Configuration — exclude patterns, self-hosted deployments, custom intercept addresses
- Feedback API — full field reference, matching strategies, sentiment values
- Supported Libraries — interception mechanisms, streaming, thread/process safety
- Dramatiq + pydantic-ai — task queue integration guide, known gaps, workarounds
Related Packages
- Frontend (Feedback Collection Widget): coolhand-js - Frontend feedback widget for collecting user feedback on AI outputs
- Ruby: coolhand gem - Coolhand monitoring for Ruby applications
- Node.js: coolhand-node package - Coolhand monitoring for Node.js applications
Community
- Questions? Create an issue
- Contribute? Submit a pull request
- Support? Visit coolhandlabs.com
About Coolhand Labs
Coolhand Labs builds observability and feedback tooling for AI-powered applications. Our platform helps teams monitor LLM usage, collect structured human feedback, and improve output quality over time — across every provider and framework.
License
Apache-2.0
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file coolhand-0.5.0.tar.gz.
File metadata
- Download URL: coolhand-0.5.0.tar.gz
- Upload date:
- Size: 73.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f8012ebd64040469bb58d35e8cd4012c087c730da25b29d18c8ba90d0f03098
|
|
| MD5 |
1dc1a3982627a65c1723bffdf0d29b11
|
|
| BLAKE2b-256 |
05ef289a9421ae002690406c43d9fca4241f211ff87e92a6a16889d000a2702f
|
Provenance
The following attestation bundles were made for coolhand-0.5.0.tar.gz:
Publisher:
publish.yml on Coolhand-Labs/coolhand-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
coolhand-0.5.0.tar.gz -
Subject digest:
0f8012ebd64040469bb58d35e8cd4012c087c730da25b29d18c8ba90d0f03098 - Sigstore transparency entry: 2297644680
- Sigstore integration time:
-
Permalink:
Coolhand-Labs/coolhand-python@b2539a5939d511cb6e43f6e892893917fde71012 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/Coolhand-Labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b2539a5939d511cb6e43f6e892893917fde71012 -
Trigger Event:
push
-
Statement type:
File details
Details for the file coolhand-0.5.0-py3-none-any.whl.
File metadata
- Download URL: coolhand-0.5.0-py3-none-any.whl
- Upload date:
- Size: 26.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
123c6a172a76c00b60957c111c850ac02e47177e12c373e48060f9755e994001
|
|
| MD5 |
87db7cebf4b4aee1a24867fb02166d1b
|
|
| BLAKE2b-256 |
4def158bd259c6aa184736906ac1a7c50811de665ea461c62dc9363337e63150
|
Provenance
The following attestation bundles were made for coolhand-0.5.0-py3-none-any.whl:
Publisher:
publish.yml on Coolhand-Labs/coolhand-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
coolhand-0.5.0-py3-none-any.whl -
Subject digest:
123c6a172a76c00b60957c111c850ac02e47177e12c373e48060f9755e994001 - Sigstore transparency entry: 2297645077
- Sigstore integration time:
-
Permalink:
Coolhand-Labs/coolhand-python@b2539a5939d511cb6e43f6e892893917fde71012 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/Coolhand-Labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b2539a5939d511cb6e43f6e892893917fde71012 -
Trigger Event:
push
-
Statement type: