Skip to main content

Official Python client for the Yesil Health AI enterprise (B2B) API.

Project description

yesil-health-ai-api (Python)

Official Python client for the Yesil Health AI enterprise (B2B) API.

Synchronous, built on httpx. The hard part of integrating — parsing the typed Server-Sent Events stream — is handled for you. Mirror of the TypeScript client @yesilsci/health-ai-api.

Install

pip install yesil-health-ai-api

Quick start

import uuid
from yesil_health import YesilHealthClient

client = YesilHealthClient(
    base_url="https://api.yesilhealth.com",
    api_key="...",  # sent as X-API-Key
)

for ev in client.chat_stream({
    "question": "Is metformin safe for a patient with stage 3 CKD?",
    "request_id": str(uuid.uuid4()),       # idempotent billing — recommended
    "demographics": {"age": 62, "sex": "female"},
    "health_context": "eGFR 45 mL/min/1.73m². On lisinopril 10mg daily.",
}):
    if ev["type"] == "delta":
        print(ev["content"], end="", flush=True)

One-shot (no live rendering):

result = client.chat({"question": "..."})
print(result["text"])

The client is a context manager:

with YesilHealthClient(base_url=..., api_key=...) as client:
    ...

Authentication

Every request is authenticated with your enterprise API key via the X-API-Key header. Keep it server-side; never ship it in a client app.

The event stream

chat_stream() yields event dicts. Route on event["type"]:

type Payload Notes
meta phase, conversation_id, research preview Lifecycle + mid-stream research previews.
delta content Append to build the answer text.
citation citation fields A literature citation.
graph data Structured chart/diagram.
memory_extracted signals Only if your tenant has extract_memory enabled.
done summary Terminal success event.
error message, code Terminal failure event.

Forward compatibility. The API only ever adds fields and event types within a contract version. Always ignore unknown type values — this client yields them as plain dicts rather than raising.

Errors

Non-2xx responses raise YesilApiError with status, code (server error_code), and message:

from yesil_health import YesilApiError

try:
    client.chat({"question": "..."})
except YesilApiError as e:
    if e.code == "RATE_LIMITED":  # 429
        ...
    if e.status == 402:           # quota exhausted / billing
        ...

Account endpoints

client.billing()  # billing status
client.quota()    # quota / rate-limit status
client.usage()    # usage report

Versioning

Targets contract v1 (/api/v1). Pass api_version="v2" to YesilHealthClient to migrate when a new major version ships. v1 is never force-killed. Kept in lockstep with the TypeScript client — see sdk/CONTRACT_SYNC.md.

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

yesil_health_ai_api-0.1.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

yesil_health_ai_api-0.1.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file yesil_health_ai_api-0.1.0.tar.gz.

File metadata

  • Download URL: yesil_health_ai_api-0.1.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for yesil_health_ai_api-0.1.0.tar.gz
Algorithm Hash digest
SHA256 473e7da34318649873d8b67e89bedac540dcb59f9cf5d93e5b6fcf61e59c528c
MD5 aeb0eb6f3e27d57307a870148edec185
BLAKE2b-256 b7d096461d289e03c5e5e59556c30a176390dc4973fb369e4525d7c23fa793d3

See more details on using hashes here.

File details

Details for the file yesil_health_ai_api-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for yesil_health_ai_api-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a48550393a02897243b1f2ca3005f380477b7d93d8e0cad16817ba52dc7939ca
MD5 ee0167e36ef67a633b4948a37e379ef2
BLAKE2b-256 2bb06ccc604b79f706a5cb2c7dae66a33158d2386892b98a855db45f2c2fcfe4

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