Skip to main content

yesil-health-ai-api (Python)

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

What the API gives you: streaming health answers grounded in scientific evidence and in your institution's own content. Answers come with inline citations, structured proposals your system applies (reminders, measurements), memory records to store, appointment/service links, and billing on every turn.

Endpoints

Point the client at the chat and document endpoints you use:

Option Endpoint
chat_endpoint /api/v2/chat/stream/compat (classic delta/citation events plus module events) or /api/v2/chat/stream (native: final answer, cards, state proposals)
document_endpoint /api/v2/documents/process (structured lab rows, quality metadata, context_block)
evidence_endpoint /api/v2/evidence/search (ranked sources with relevance, no AI answer)

The router picks the modules each message needs (memory, measurements, reminders, scientific evidence, institution knowledge, appointment handoff and service matching) and returns them as additive events. Unknown events stay safe to ignore. The full reference is the API guide in the Yesil Health console.

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
    chat_endpoint="/api/v2/chat/stream/compat",
)

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.
memory_extracted signals Records to store; send them back in memory.
state_patch status, operations Native action proposals; apply in your system and deduplicate by operation id.
reminder_action / measurements_extracted status, operation_id, action Compat record proposals; apply once per operation_id.
handoff_recommendation status, action Compat: verified institution link; no booking or live transfer.
service_recommendation status, action Compat: approved catalog selection; no purchase or booking.
answer markdown, blocks, follow_up, references Native V2 final snapshot of the deltas already streamed.
card card_type, payload, markdown_fallback Native V2 structured card, normalized by this SDK.
done summary, billing, usage Terminal event. V2 billing.cost_usd is the final customer charge; usage.worker_summary contains content-free worker outcomes.
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
        ...

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

Compat and native

Compat (/api/v2/chat/stream/compat) streams delta and citation events with [n] markers, plus reminder_action / measurements_extracted proposals (apply once per operation_id) and handoff_recommendation / service_recommendation links. The answer text also contains the link, so don't render the same call-to-action twice.

Native (/api/v2/chat/stream) adds state_patch proposals, card events and a final answer snapshot. Replace the streamed message with the snapshot if you need it; don't append it as a second message.

Both chat endpoints end each turn with done.billing (charged lines, each with the module and result that triggered it) and done.usage (module names, outcome codes, durations and counts; never patient text or source titles). Exact rates come from your institution's rate card.

Your system owns patient state: store memory_extracted records and applied proposals, and send the current reminders and relevant context on later turns. See Conversation state in the console API guide. Document processing returns a context_block to send as health_context; unusable results are not charged.

client = YesilHealthClient(
    base_url="https://api.yesilhealth.com",
    api_key="...",
    chat_endpoint="/api/v2/chat/stream",
    document_endpoint="/api/v2/documents/process",
)

doc = client.parse_document(open("lab.pdf", "rb"), document_hint="auto")
# Keep doc["context_block"] in your own patient context and send it as health_context.

Full reference: the API guide in the Yesil Health console (API Docs).

Metadata

Release files for yesil-health-ai-api 0.5.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yesil-health-ai-api 0.5.3
File Size Uploaded Provenance
yesil_health_ai_api-0.5.3.tar.gz 11.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for yesil-health-ai-api 0.5.3
File Interpreter ABI Platform
yesil_health_ai_api-0.5.3-py3-none-any.whl Python 3 none any Details

Total release size: 23.8 kB

Release files / yesil_health_ai_api-0.5.3.tar.gz

Download URL yesil_health_ai_api-0.5.3.tar.gz
Size 11.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5520fa6b6dfa36b4a70a7e5a7c70c25adbd3455304398e5953393681cba993db
BLAKE2b-256 checksum
How to use checksums
8127d5a3d17d2f6cdc4fce09b8e2ec168046dc83d295e27b4216e803bd858cce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / yesil_health_ai_api-0.5.3-py3-none-any.whl

Download URL yesil_health_ai_api-0.5.3-py3-none-any.whl
Size 12.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bea549e14882dce81c95748bbaeba77c84805dc3a5a8c1381b643d89c2e6db81
BLAKE2b-256 checksum
How to use checksums
b554a127f12c341a046918ca698067ae5ec0d592f1b52a91b637ba2cfb2d36de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Security for yesil-health-ai-api 0.5.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page