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
        ...

Evidence search

Ranked literature retrieval for a query, no LLM answer synthesis. Requires the evidence:read scope on your API key.

res = client.evidence_search({
    "question": "omega-3 and cardiovascular risk reduction",
    "needs_trials": False,
})
print(res["papers"])

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.2.0.tar.gz (7.4 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.2.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: yesil_health_ai_api-0.2.0.tar.gz
  • Upload date:
  • Size: 7.4 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.2.0.tar.gz
Algorithm Hash digest
SHA256 79915f97ff84331058e4c031bf56d69068633fbbd42c9ff3d37312b9ec1b8c5b
MD5 69a0184faf5fab9a2768d5b513637429
BLAKE2b-256 ff8b8814339c3ba407fedf12ce6f83c21111570f93675b6d5ec1387828e27b64

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for yesil_health_ai_api-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1253feffec37a6b9eeb7c5a46a2d138917606ea0fce8b1f292904efd69a2e7c7
MD5 18185e22a7319be37f63202f85c257d1
BLAKE2b-256 d4ba82f9b063df28081a783125c1094399f0acf0dd78d18101adf4cc6b0b8858

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