Lightweight health checks for OpenAI
Project description
ai-healthcheck
Lightweight health checks for OpenAI — no heavy SDKs required.
- Minimal data-plane calls with tiny payloads and short timeouts
- Clear, predictable behavior (always returns
HealthResult) - Small install footprint (uses
requestsonly) - Perfect for application startup probes and CI/CD smoke tests
Installation
pip install ai-healthcheck
Quickstart
Set your credentials (example using environment variables), then call the check.
import os
from ai_healthcheck import check_openai
res = check_openai(
endpoint=os.environ["OPENAI_ENDPOINT"], # e.g., https://api.openai.com
api_key=os.environ["OPENAI_API_KEY"],
model="gpt-4o-mini",
)
print(res)
Sample output
# HealthResult(provider='openai',
# endpoint='https://api.openai.com',
# ok=True,
# status_code=200,
# message='OpenAI reachable. Credentials and model appear valid.')
Usage
from ai_healthcheck import check_openai
res = check_openai(
endpoint="https://api.openai.com",
api_key="***",
model="gpt-4o-mini",
timeout=10.0,
)
print(res.ok, res.status_code, res.message)
Behavior:
- 200 -> ok=True
- else (401/403 and other non-2xx, or network errors) -> ok=False with details
Notes
- Uses
requestsonly; no SDK dependency. - No custom User-Agent header is set (keep requests minimal).
Troubleshooting
- 404: API key may be valid, but the endpoint/path or model name is likely incorrect. Verify the endpoint (e.g., include
/v1only once) and the model. - 401/403: Authentication/permission errors. Check API key and account access.
CI/CD and startup probes
Use these checks in your pipelines or app startup to fail fast with clear guidance.
def app_startup_probe():
from ai_healthcheck import check_openai
res = check_openai(endpoint=..., api_key=..., model=...)
if not res.ok:
raise RuntimeError(f"OpenAI health check failed: {res.message}")
Contributing
Contributions are welcome! Please open issues and pull requests on GitHub.
Project details
Release history Release notifications | RSS feed
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 ai_healthcheck-0.1.0a1.tar.gz.
File metadata
- Download URL: ai_healthcheck-0.1.0a1.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c4281e8607f8e76f9345a2fe81b0c739b41f7fc75ccc7e7b4839dfdb1ceaa8e
|
|
| MD5 |
5e071e5138dfbef33dc19568aaffb6f5
|
|
| BLAKE2b-256 |
b76d3dd38f0ff5c3201b7d8acf007e8ca6036d291dcc1734ebdfd77376ef8d7c
|
File details
Details for the file ai_healthcheck-0.1.0a1-py3-none-any.whl.
File metadata
- Download URL: ai_healthcheck-0.1.0a1-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0fab0e6be0d1d057181fd0ef67de63a7886315b4e42f2da2401543448156a508
|
|
| MD5 |
2eb2e0d31f9631669e7f42648b2ce9e8
|
|
| BLAKE2b-256 |
b6d66d7c94d560cba7d24f589a05bd74c279a36134622cf6d31a6a3589cc02ce
|