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 backend/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.1.tar.gz (6.5 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.1-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: yesil_health_ai_api-0.1.1.tar.gz
  • Upload date:
  • Size: 6.5 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.1.tar.gz
Algorithm Hash digest
SHA256 eff2478f9e7237569502bfd0395f03458b64174e1cdc0143117919b8870c0a11
MD5 62e46d2008d4314c38249fb8129ddb44
BLAKE2b-256 9c66553c45af275a3300ace297dd223058a7349aa8d116776c7e2f79ff6409cb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for yesil_health_ai_api-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b6587d51dfa5547794d8720c505f7779664e566a480a03fe35322fa4f77c38f5
MD5 97729bff3e031f5c78672928f1f4bdef
BLAKE2b-256 9bc963463813ff39d092ed96d00767fa8efb4a2e92cc3e02de2799a28ad17794

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