Skip to main content

Lightweight health checks for OpenAI

Project description

ai-healthcheck

Python package License: MIT Downloads Downloads

GitHub contributors GitHub issues GitHub pull-requests PRs Welcome

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 requests only)
  • 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",
    # Optional: scope to an organization if your account uses one
    # org_id=os.environ.get("OPENAI_ORG_ID"),
)
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",
    # Optional organization header
    # org_id="org_12345",
    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 requests only; 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 /v1 only 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ai_healthcheck-0.1.1a1.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ai_healthcheck-0.1.1a1-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file ai_healthcheck-0.1.1a1.tar.gz.

File metadata

  • Download URL: ai_healthcheck-0.1.1a1.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for ai_healthcheck-0.1.1a1.tar.gz
Algorithm Hash digest
SHA256 9e37ce21c66772cd53102bca17eb9c43888422b41a00855c0d4f27ca574b008f
MD5 fc5bbcec6524d752149ab5ee89bc9101
BLAKE2b-256 8e5051e72c600ed33d066770f63aacb0a06286c96ff13609ca12a3f508acc8c4

See more details on using hashes here.

File details

Details for the file ai_healthcheck-0.1.1a1-py3-none-any.whl.

File metadata

File hashes

Hashes for ai_healthcheck-0.1.1a1-py3-none-any.whl
Algorithm Hash digest
SHA256 c9c23ecbd0289951d1b0db5be0fe040a7a4f15e50055ce5e02470fb73aca6e67
MD5 eba38c0c95306d00edba6dc903d8e9d8
BLAKE2b-256 295b6c6a3401281afa501c299621bbc9aa5646c1970c5a6f96019964c629f41a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page