Hikigai

AppSDK

Application SDK

Lightweight SDK for invoking healthcare AI agents in your medical applications and EHR systems.HIPAA-ready, fast, and production-ready with streaming responses for clinical workflows and session support for patient consultations.

v0.2.11Python 3.10+StreamingSessionsWebSocket

Installation

Using pip

pip install hikigai-appsdk

Sign in on your computer

To run your code on your computer, sign in once with your Hikigai account. There is no key to copy. Installing hikigai-appsdk gives you the hikigai command.

hikigai login                 # opens the browser: pick the project, check the code, Approve
hikigai login --project <id>   # or name the project here

You get a sign-in for one project that lasts 6 hours, with your role in that project. It is saved on your computer (~/.hikigai/credentials.json, readable only by you) and AppClient() uses it automatically: invoke, stream, live voice, rooms, speech, MCP, and deploy / manage if your role allows. Python and Node.js share the same sign-in.

hikigai whoami    # who, which project, time left
hikigai token     # print the token (curl / Postman: Authorization: Bearer <token>)
hikigai logout    # end it now
  • After 6 hours, run the login again. For another project, log in again with that project.
  • See or end your sign-ins in the console under CLI logins.
  • It does not work inside a deployed App. There the platform gives your App its own key, so the same code runs unchanged.

Quick Start

Credentials: nothing to paste.
  • On your computer: run hikigai login once (seeSign in on your computer). ThenAppClient() with no arguments uses that sign-in.
  • In your deployed App: the platform sets HIKIGAI_API_KEY (a hidden Deploy key), HIKIGAI_PROJECT_ID, HIKIGAI_APP_ID and HIKIGAI_PLATFORM_URL. The SDK swaps the key for a 5-minute token at POST /api/v1/auth/exchange and renews it.

The same code runs in both places. There are no project API keys to manage (old ones get PROJECT_KEYS_REMOVED). See API Reference → Authentication.

import asyncio
from hikigai.appsdk import AppClient

# No arguments. On your computer it uses your `hikigai login`; inside the deployed App
# the platform sets HIKIGAI_API_KEY (Deploy key), HIKIGAI_PROJECT_ID, HIKIGAI_APP_ID and
# HIKIGAI_PLATFORM_URL, and the SDK exchanges the key for a token it renews.
client = AppClient()

# Get an agent by slug or id
agent = client.agent("medical-coder")

# Invoke
response = agent.invoke("Patient presents with fever and cough...")
print(response.content)

# Stream
for chunk in agent.stream("Tell me about diabetes"):
    print(chunk, end="", flush=True)

# Session-based conversations
session_agent = agent.with_session("user-123")
session_agent.invoke("What is hypertension?")
session_agent.invoke("How is it treated?")  # Remembers context

# Live WebSocket (install: pip install websockets)
async def live():
    async with client.live(agent.slug, user_id="app-user") as session:
        await session.send_text("Hello")
        async for event in session:
            print(event)
            if event.get("type") in ("turn_complete", "end"):
                break

asyncio.run(live())

Client Reference

class AppClient

AppClientCore

Main client for invoking AI agents. Manages authentication, HTTP connections, and provides access to deployed agents.

Constructor

client = AppClient(
    api_key: Optional[str] = None,        # Leave unset inside a deployed App: the platform sets
                                          # HIKIGAI_API_KEY (Deploy key). Runtime calls need it
    project_id: Optional[str] = None,     # Project ID (or HIKIGAI_PROJECT_ID env var)
    base_url: Optional[str] = None,       # defaults to HIKIGAI_PLATFORM_URL; leave unset inside a deployed App
    timeout: float = 30.0,                # Request timeout in seconds
    sona_url: Optional[str] = None,       # Optional SONA service URL
    sona_api_key: Optional[str] = None,   # Optional SONA API key
)

Methods

MethodReturnsDescription
agent(agent_id: str)RuntimeAgentGet agent by ID or slug for invocation
list_agents(category=None, tags=None, search=None)List[RuntimeAgent]List available agents with optional filters
invoke(agent_id, input, session_id=None, provider=None, model=None, connectors=None, plugin_context=None)InvokeResponseInvoke an agent without fetching RuntimeAgent first
live(agent_id, session_id=None, user_id='sdk-user', context=None, connectors=None)StreamSessionOpen a live WebSocket session (optional MCP connectors)
create_session(external_user_ref=None, ttl_seconds=None, app_id='_', metadata=None)SessionContextCreate a server-side session context store
session(session_id, app_id='_')SessionContextAttach to an existing session context
list_sessions(user_ref=None, limit=50, cursor=None)DictList session contexts
get_auth_token()Dict[str, Any]POST /api/v1/auth/exchange: 5-minute workload token, bound to this App and deployment; the SDK gets it for you and renews it before it expires

Properties

identity()IdentityClientEnd-user auth (Cognito, MFA, QR, SSO)
sona()SONAClientSONA personalization (edits, preferences, suggestions)
storage()StorageClientApp object storage
notifications()NotificationsClientNotifications to phones, browsers and other apps (see Notifications)

Context Manager

with AppClient() as client:
    agent = client.agent("my-agent")
    response = agent.invoke("Hello")
# Resources automatically released

Agent Reference

class RuntimeAgent

RuntimeAgentModel

Represents a deployed agent ready for invocation. Provides methods for synchronous invocation, streaming, and session management.

Properties

PropertyTypeDescription
idstrUnique agent ID
namestrAgent name
slugstrURL-friendly slug
versionstrAgent version
descriptionstr | NoneAgent description
statusstrDeployment status ('active', 'pending', etc.)
endpointstr | NoneInvocation endpoint URL

Methods

MethodReturnsDescription
invoke(input, session_id=None, provider=None, model=None, timeout=None, connectors=None, plugin_context=None)InvokeResponseInvoke agent synchronously with optional session, MCP connectors, and plugins
stream(input, session_id=None, provider=None, model=None, connectors=None)Iterator[str]Stream agent response chunks in real-time (SSE)
with_session(session_id: str)RuntimeAgentCreate agent instance with persistent session
live_session(session_id=None, *, connectors=None, context=None, user_id='sdk-user')StreamSessionOpen a bidirectional WebSocket live session (optional MCP connectors)

Basic Usage

agent = client.agent("medical-coder")

# Synchronous invocation
response = agent.invoke("Patient has diabetes...")
print(response.content)

# With MCP connectors + SONA plugin context
response = agent.invoke(
    "Prepare patient chart",
    connectors={"my-ehr-connector": {"headers": {"Authorization": "Bearer ..."}}},
    plugin_context={"sona": {"user_id": "dr-smith-uuid"}},
)

# Streaming
for chunk in agent.stream("Explain hypertension"):
    print(chunk, end="")

# With session
response = agent.invoke("My name is Alice", session_id="user-123")
response = agent.invoke("What's my name?", session_id="user-123")  # Remembers "Alice"

Workflow agents (including those that reuse marketplace leaves via AgentSDK source="marketplace") are invoked the same way — use the root agent's slug or id.

Response Types

class InvokeResponse

InvokeResponsePydantic Model

Response from a synchronous agent invocation containing output content and metadata.

PropertyTypeDescription
content*strAgent output content
agent_idstrID of the agent that responded
agent_versionstr | NoneVersion of the agent
session_idstr | NoneSession ID if used
statusstrStatus (success, requires_human_review, etc.)
outputDict | NoneStructured agent output when available
confidenceClinicalConfidence | NoneClinical confidence score (0–1)
safety_flagsList[SafetyFlag]Safety flags (severity: low|medium|high|critical)
citationsList[ClinicalCitation]Evidence-based clinical citations
metadataInvocationMetadataInvocation metadata (latency, tokens, etc.)
messagestr | NoneOptional warning or info message
pluginsDict | NonePlugin metadata (e.g. plugins['sona'])

Example

response = agent.invoke("Hello")

print(response.content)                    # "Hi! How can I help you?"
print(response.status)                     # "success"
print(response.metadata.latency_ms)        # 234
print(response.metadata.tokens_used)       # 156
print(response.metadata.tools_called)      # ["web_search"]
print(response.plugins)                    # {"sona": {"output_id": "..."}}

class InvocationMetadata

InvocationMetadataPydantic Model

Metadata about an agent invocation including performance metrics and execution details.

invocation_idstrUnique invocation ID
latency_msint | NoneResponse latency in milliseconds
timestampdatetimeInvocation timestamp
statusstrStatus ('success', 'error', etc.)
tokens_usedint | NoneTotal tokens consumed
tools_calledList[str]Tools used (from top-level gateway tools_called — includes MCP CallTool on Sequential/Parallel/Loop leaves)
phi_redactedboolWhether PHI was redacted
trace_idstr | NoneTrace ID for troubleshooting

MCP on Workflow Agents

Deploy a Sequential / Parallel / Loop agent with root connectors in AgentSDK → MCP on Sub-Agents. Then pass the same connector map on invoke or live. MCP tools attach to every LlmAgent leaf. Check metadata.tools_called (populated from the gateway top-level field) to confirm CallTool ran.

from hikigai.appsdk import AppClient

client = AppClient()  # inside the deployed App
agent = client.agent("vitals-fetch-subagent")

# Same connectors shape for simple LLM roots and Sequential leaves
response = agent.invoke(
    {"site_id": 1, "patient_id": "PATIENT001"},
    connectors={"idexx-mcp-server": {}},
    timeout=120,
)

print(response.content)                      # summary text / {"response": "..."}
print(response.metadata.tools_called)        # e.g. ["get_vitals_for_today"]
print(response.metadata.latency_ms)

# Live WebSocket — MCP on leaves too
# async with client.live(
#     "vitals-fetch-subagent",
#     connectors={"idexx-mcp-server": {}},
# ) as session:
#     await session.start(modality="text")
#     await session.send_text("Fetch today's vitals")
#     async for event in session:
#         if event.get("type") == "tool_call":
#             print(event)  # leaf CallTool frames
Note: Plain-text Sequential answers may be wrapped as {"response": "..."} so schema retries do not re-fire MCP. Empty tools_called with MCP server logs showing CallTool usually means an outdated AppSDK — upgrade and re-check top-level gateway fields.

Call an MCP Server Directly

To call one of your MCP servers yourself (not through an agent), ask Hikigai for an MCP token: a ticket that works for 1 hour, for that one server only. Then call the server's mcp_url with it, using the official mcp package. AppClient signs in for you: in the deployed App it uses the App's key, on your computer your hikigai login.

# pip install mcp
from hikigai.appsdk import AppClient
from mcp import ClientSession
from mcp.client.streamable_http import streamablehttp_client

client = AppClient()

# 1. MCP token for one server -> {"token", "header", "mcp_url"}
ticket = client.api.post("/api/v1/mcp/access-token", json={"server": "my-mcp-server"})

# 2. Call the MCP server with it
async with streamablehttp_client(ticket["mcp_url"], headers={ticket["header"]: ticket["token"]}) as (read, write, _):
    async with ClientSession(read, write) as mcp:
        await mcp.initialize()
        tools = await mcp.list_tools()
        result = await mcp.call_tool("my_tool", {"query": "hello"})
Note: Reuse the ticket. When the MCP server answers 401 (after 1 hour), get a new one. Agents don't need this: pass connectors and Hikigai signs the MCP calls. Without the SDK, see API reference → MCP Servers.

Warming Up Agents

Agents set to scale to zero stop after a period without traffic (30 minutes by default), and the next invoke waits while the agent starts, up to a few minutes. warmup() starts agents early so the first real request finds them running. It is optional.

# Returns right away; the platform starts the agents in the background.
client.warmup(["medical-coder", "scribe"])

# Omit the list to warm every scale-to-zero agent this project can call.
client.warmup()

# Wait until they are up (polls every 5 s, gives up after 5 min).
[coder] = client.warmup(["medical-coder"], wait=True, timeout=300)
print(coder.status)  # "ready", or still "warming" at the timeout

# One agent
client.agent("medical-coder").warmup()

# Start warming as soon as the App starts
client = AppClient(warm_agents=["medical-coder"])  # or warm_agents="all"

# Check later
client.warmup_status(["medical-coder"])  # status + live_state (running, scaled_to_zero, ...)

Each result has a status: warming, ready, failed (the first invoke cold-starts as usual), not_applicable (for example Lambda), not_found, or not_requested from warmup_status(). Call it shortly before users need the agent, such as at sign-in. A warm-up counts as activity, so an agent nobody invokes still goes back to zero after the idle window.

warmup_status() also returns live_state, what the agent is doing right now whether or not a warm-up was requested: running, starting, stopping, scaled_to_zero (AWS ECS, with the task counts), on_demand (Cloud Run, Lambda), or empty when unknown.

Live WebSocket Sessions

Deploy first with AgentSDK. For Sequential / Parallel / Loop live agents, configure leaves with live_handoff when deploying (see AgentSDK → Workflow Agents). To reuse a marketplace agent as a leaf, deploy with source="marketplace" + name (documented under SubAgentConfig). AppSDK only opens the session — it does not define workflow structure.

Bidirectional realtime via StreamSession. Flow: auth/exchange → POST …/live/session → WebSocket at the returned wss_url (…/live) → binary PCM (protocol v2). Captions use source: input_transcription; replace pending text on partials. Requires the optional websockets dependency. Full protocol: API Reference → Live Sessions.

import asyncio
from hikigai.appsdk import AppClient

async def main():
    client = AppClient()  # deployed App: Deploy key → workload token, cached and refreshed
    # AppSDK generates session_id if omitted; always mints with {session_id, user_id}

    async with client.live("YOUR_AGENT_SLUG", user_id="app-transcriber") as session:
        await session.start(modality="audio", mime_type="audio/pcm;rate=16000")
        await session.send_data(pcm_bytes)  # raw bytes → binary frames

        async for event in session:
            if event.get("source") == "input_transcription":
                print(event["content"])  # replace UI on partials
            if event.get("type") == "end":
                break

        await session.end()

asyncio.run(main())

Attach MCP tools on live the same way as invoke: pass connectors. Mint then uses the gateway /live path so connectors resolve before bidirectional run_live.

async with client.live(
    "clinical-live-agent",
    user_id="app-user",
    connectors={"my-ehr-connector": {}},  # same shape as invoke
) as session:
    await session.send_text("Look up the patient chart")
    async for event in session:
        if event.get("type") == "tool_call":
            print(event)
        if event.get("type") in ("turn_complete", "end"):
            break

Speech: Translate & Transcribe

Real-time speech-to-speech translation and speech-to-text transcription via client.speech. These are not agents — nothing to deploy, and no agent slug. Available to team organizations with GCP connected, billed to your own cloud project. Full protocol: API Reference → Speech.

Translate

import asyncio
from hikigai.appsdk import AppClient

async def main():
    client = AppClient()  # deployed App: credentials set by the platform

    session = await client.speech.translate(
        target_language="es",
        echo_target_language=True,   # default: echo when input is already Spanish
        input_transcription=True,    # default
        output_transcription=True,   # default
    )

    async def send():
        # Any source format — converted to 16 kHz mono PCM for you.
        async for chunk in phone_call():
            await session.send_audio(chunk, encoding="mulaw", sample_rate=8000)

    asyncio.create_task(send())

    async for event in session:
        if event.type == "audio":
            speaker.write(event.audio)          # 24 kHz PCM
        elif event.type == "transcript":
            print(event.source, event.text, event.language_code)     # "input" / "output"

asyncio.run(main())

Transcribe

session = await client.speech.transcribe(
    languages=["en-US", "es-ES"],               # optional; omit to auto-detect
    custom_vocabulary=["Hikigai", "Kubernetes"],
)

await session.send_audio(pcm_16k)               # already 16 kHz mono PCM

async for event in session:
    if event.type == "transcript":
        print(event.text, event.language_code, "final" if event.final else "interim")

Note the code shapes differ: translate takes bare subtags (es), transcribe takes full locales (es-ES). Google caps transcription at 10 minutes; the gateway rotates the upstream transparently, so long sessions need no handling.

Changing language mid-conversation

Returns once the new language is live. A replacement model session is brought up before the old one is retired, so audio keeps flowing and the listener hears no gap.

await session.set_language("fr")   # no reconnect, no new token

Audio helpers

send_audio converts for you, but the helpers are exported for callers doing their own buffering.

from hikigai.appsdk import to_model_audio, chunk_audio, pcm_to_wav

pcm = to_model_audio(raw, encoding="mulaw", sample_rate=8000)  # telephony → 16 kHz
pcm = to_model_audio(raw, encoding="f32", sample_rate=48000)   # browser Float32
pcm = to_model_audio(raw, sample_rate=48000, channels=2)       # stereo → mono

for chunk in chunk_audio(pcm):        # ~100 ms frames, never splits a sample
    await session.send_audio(chunk)

open("out.wav", "wb").write(pcm_to_wav(translated))  # 24 kHz by default

Browser and mobile clients

Mint a short-lived token from your deployed App so no platform credential reaches the client.

token = client.speech.mint_token(
    "translate",
    target_language_code="ja",
    locked=True,   # pin the config — client cannot call configure
)
# Hand token["speech_token"] to the browser; it connects directly.
Try it first: the Voice Lab tab in your project console runs both endpoints from the browser and generates this code from whatever config you settle on.

Session Context Store

Server-side key/value context for apps (SessionContext), separate from conversation session_id memory on invoke.

# Create a context store
ctx = client.create_session(external_user_ref="dr-smith", ttl_seconds=3600)
ctx.set("patient_id", "MRN-12345")
ctx.set("visit_id", "V-99", if_match=None)

print(ctx.get("patient_id"))
print(ctx.get_all())
print(ctx.metadata())

# Attach later
ctx = client.session(ctx.session_id)
ctx.update({"chief_complaint": "chest pain"})
ctx.touch(ttl_seconds=7200)
ctx.delete("visit_id")
ctx.clear()

Session Management

Maintain conversation context across multiple invocations using sessions. Sessions enable multi-turn conversations where the agent remembers previous interactions.

Per-Invocation Sessions

Pass a session_id to each invocation to maintain context.

agent = client.agent("chatbot")

# First message
response1 = agent.invoke(
    "My name is Alice",
    session_id="user-123"
)

# Follow-up - agent remembers the name
response2 = agent.invoke(
    "What's my name?",
    session_id="user-123"
)
print(response2.content)  # "Your name is Alice"

Persistent Session Agent

Create a session-bound agent using with_session(). All invocations automatically use the same session.

agent = client.agent("assistant")

# Create session-bound agent
session_agent = agent.with_session("user-456")

# All invocations share the same session
session_agent.invoke("I live in New York")
session_agent.invoke("What's the weather like here?")  # Knows "here" = NYC

# Streaming works too
for chunk in session_agent.stream("Tell me more about my city"):
    print(chunk, end="")

Multiple Users

Maintain separate contexts for different users with different session IDs.

agent = client.agent("support-bot")

# User 1's conversation
user1 = agent.with_session("user-001")
user1.invoke("I'm having trouble logging in")

# User 2's isolated conversation
user2 = agent.with_session("user-002")
user2.invoke("How do I reset my password?")

# Contexts are completely separate
# User 1's issues don't affect User 2's conversation

Rooms & WebRTC

Use SFU (connect_media) for audio, video, and in-call text; RoomSession for WebSocket pub/sub (transcripts, presence, app events).

PathSignallingMediaBest for
SFUHTTP media-token + WHIPBrowser ↔ hikigai-mediaMulti-party audio, video, text
WebSocket roomsWS join / publish—Transcripts, presence, app events
Note: connect_media mints token + ICE only — drive WHIP with your WebRTC client. Frame-level SFU (aiortc), not packet-forwarding.

SFU mode

connect_media mints the token + ICE config. Then join with your WebRTC client. No rooms WebSocket required for audio, video, or DataChannel chat.

import os
from hikigai.appsdk.rooms import connect_media

# inside the deployed App
media = await connect_media(
    base_url=os.environ["HIKIGAI_PLATFORM_URL"],
    room="call-123",
    api_key=os.environ["HIKIGAI_API_KEY"],
    project_id="proj_...",
)

print(media["token"], media["sfu_url"], media["ice_servers"])
print(media.get("turn_source"))  # managed | byo | stun_only
# sfu_url is platform-provided — POST offer to {sfu_url}/rooms/{room}/join (don't hardcode)

# Optional one-off BYO TURN for this token:
# await connect_media(..., ice_servers=[{"urls": ["turn:…"], "username": "…", "credential": "…"}])
TURN options
  • • Default: Hikigai-managed STUN/TURN in ice_servers
  • • Org BYO: Organization settings → WebRTC TURN
  • • Per call: pass ice_servers= to connect_media

See: API → WebRTC · TURN / ICE.

WebSocket rooms

Create and use multi-party realtime rooms with RoomSession — JSON pub/sub for transcripts, presence, and app events. Standalone (not on AppClient). Requires websockets.

Full method list and frame types: AgentSDK → RoomSession. Protocol details: API reference → Rooms.

Create, join, publish

import asyncio
import os
from hikigai.appsdk import RoomSession

async def main():
    # Inside the deployed App: HIKIGAI_API_KEY / HIKIGAI_PROJECT_ID are set by the platform
    room = RoomSession(base_url=os.environ["HIKIGAI_PLATFORM_URL"], api_key=os.environ["HIKIGAI_API_KEY"])
    async with room:
        await room.join("care-team-7")  # creates the room if new
        await room.publish("care-team-7", "note", {"text": "Labs ready"})
        await room.who("care-team-7")
        async for frame in room:
            if frame.get("type") == "message":
                print(frame["event"], frame["data"])
            elif frame.get("type") == "error":
                print(frame.get("code"), frame.get("message"))
                break

asyncio.run(main())

Auth

Pass exactly one of api_key, access_token, or room_token, plus project_id when using a key/JWT. End-user tokens are scoped to specific rooms and capabilities. Your App's workload token (from the Deploy key) gets full access in that project; on your computer, a hikigai login token gets the same within your role.

Even Realities G2 Glasses Integration

Build apps for Even Realities G2 smart glasses with a Python proxy that keeps your API key private. G2 apps run in the Even phone app WebView and drive the 640×350 green monochrome display via @evenrealities/even_hub_sdk. The glasses UI is always TypeScript; Python (or raw HTTP) only replaces the proxy. Full WebView / event loop: Node.js AppSDK G2 Guide. Console HTTP APIs: API Reference → Even G2. Starter (Node UI + Express): templates/even-g2.

Environment variables

The proxy runs as a deployed Hikigai App. The platform sets HIKIGAI_API_KEY (Deploy key), HIKIGAI_PROJECT_ID, HIKIGAI_APP_ID and HIKIGAI_PLATFORM_URL (managed, cannot be overridden). Set HIKIGAI_AGENT_ID under Environment in the console. Optional: GLASSES_PAGE_CHARS (starter default 420). Agent calls work from the deployed App, or from your computer after hikigai login.

app.json & voice notes

  • name ≤ 20, tagline ≤ 50; permissions typically network + g2-microphone.
  • Voice requires an agent with audio in its input modalities; list/text questions work with any text agent.
  • Send WAV via attachments (mime_type="audio/wav"), not an input_audio content array.

SDK helpers (pure, no network)

from hikigai.appsdk import (
    validate_even_g2_manifest,  # same app.json rules as the deploy pipeline
    paginate_for_glasses,       # split agent answers into display-sized pages
    normalize_for_glasses,      # strip markdown decorations agents emit
    even_g2_dev_mode_url,       # validate the live URL used in the dev-mode QR
    EVEN_G2_DISPLAY,            # {"width": 640, "height": 350}
    EVEN_G2_MAX_TEXT_CHARS,     # 2000 (official text-heavy template cap)
)

check = validate_even_g2_manifest(json.load(open("app.json")))
if not check.valid:
    raise SystemExit(check.error)

pages = paginate_for_glasses(response.content, max_chars=420)
qr_payload = even_g2_dev_mode_url(live_url)

1. Proxy API with Pagination

The proxy receives queries from the WebView, invokes the agent, and returns pages sized for the G2 display.

import os
from fastapi import FastAPI
from pydantic import BaseModel
from hikigai.appsdk import AppClient, normalize_for_glasses, paginate_for_glasses

app = FastAPI()
client = AppClient()  # reads HIKIGAI_API_KEY / HIKIGAI_PROJECT_ID
PAGE_CHARS = int(os.environ.get("GLASSES_PAGE_CHARS", "420"))
AGENT_ID = os.environ["HIKIGAI_AGENT_ID"]

class AskRequest(BaseModel):
    question: str
    sessionId: str | None = None

@app.post("/api/ask")
async def ask(req: AskRequest):
    agent = client.agent(AGENT_ID)
    response = agent.invoke(req.question, session_id=req.sessionId)

    clean = normalize_for_glasses(response.content)
    return {
        "answer": response.content,
        "pages": paginate_for_glasses(clean, max_chars=PAGE_CHARS),
        "sessionId": response.session_id,
    }

2. Voice Queries (WAV attachments)

Forward base64 WAV from the glasses mic via attachments. The agent must allow audio in its input modalities — text-only agents reject voice. List/preset text questions work with any text agent.

class AudioRequest(BaseModel):
    audio_base64: str
    mime_type: str | None = "audio/wav"
    sessionId: str | None = None

@app.post("/api/ask-audio")
async def ask_audio(req: AudioRequest):
    agent = client.agent(AGENT_ID)
    response = agent.invoke(
        "Answer the question in this recording.",
        session_id=req.sessionId,
        attachments=[{
            "data_base64": req.audio_base64,
            "mime_type": req.mime_type or "audio/wav",
        }],
    )

    clean = normalize_for_glasses(response.content)
    return {
        "pages": paginate_for_glasses(clean, max_chars=PAGE_CHARS),
        "sessionId": response.session_id,
    }

Multi-Cloud Deployment

client.cloud exposes the deployment catalog and BYOC credentials. Apps, agents, and MCP servers deploy to GCP or AWS targets from the same catalog.

from hikigai.appsdk import AppClient

# management call from your computer, after `hikigai login`
client = AppClient()

catalog = client.cloud.catalog(workload="app")
for service in catalog.services:
    print(service.id, service.display_name, service.regions[0].id)

result = client.cloud.validate_target(
    workload="app",
    service_id="gcp-cloud-run",
    region="europe-west1",
    config={"cpu": "2", "memory": "1Gi"},
)

Events & Webhooks

client.events is the SDK surface for the platform event bus — HMAC-signed webhooks (at-least-once) andevents.stream() (at-most-once).

sub = client.events.create_webhook(
    url="https://ci.example.com/hooks/hikigai",
    event_types=["agent.deployed", "agent.deleted"],
    description="deploy notifications",
)
print(sub.secret)  # shown once — store it

# Live stream
async with client.events.stream(patterns=["job.*", "agent.deployed"]) as stream:
    async for event in stream:
        print(event.type, event.data)

Notifications

client.notifications sends notifications to phones, browsers and other apps, now or on a schedule. It works inside a deployed App (its own credentials) and after hikigai login. A deployed App publishes to topics that list it; you create topics and choose who may publish on the project's Notifications tab. Phones register themselves through their gateway; see API Reference → Mobile notifications.

Methods

MethodReturnsDescription
publish(*, topic=None, title=None, body=None, users=None, devices=None, app_id=None, segment_id=None, data=None, image_url=None, options=None, conversion_event=None, idempotency_key=None)DictQueue a message (status 'queued'); delivery runs in the background. Without users / devices / app_id / segment_id it goes to the topic's subscribers. {{ name }} in title and body is filled from each user's facts.
get(notification_id)DictA message this App sent, with delivery counts (stats)
list(*, topic=None, limit=50)List[Dict]Recent messages this App sent
deliveries(notification_id, *, status=None)List[Dict]Per device / webhook delivery log of one message
cancel(notification_id)DictStop deliveries that have not gone out yet
schedule(*, message, kind='once', run_at=None, recurrence=None, timezone_mode='fixed', timezone='UTC', start_date=None, end_date=None, name=None)DictSend later or on repeat. message takes what publish takes, as a dict in the API's field names (topic, title, body, data, options, target)
list_schedules / pause_schedule / resume_schedule / delete_schedule(schedule_id)Dict / ListThis App's schedules
register_browser(*, subscription, user_id=None, timezone=None, language=None, topics=None)DictRegister a browser's push subscription (PushSubscription.toJSON()) for a user, from your web app's backend
web_push_public_key()strThe organization's public web push key, for the browser's subscribe call
subscribe / unsubscribe(topic, *, user_id=None, device_ids=None)DictPut all of a user's devices (or given devices) on a topic that lets apps subscribe
devices(user_id)List[Dict]A user's registered phones and browsers
remove_device(device_id)DictStop sending to a device this App registered
topics()List[Dict]The organization's topics; can_publish says whether this App may publish
set_user_properties(user_id, properties, *, replace=False)DictFacts about a user (plan, first_name…) for placeholders and segments. Merged; None removes a fact
link_users / unlink_user(alias, user_id | alias)DictTwo IDs for the same person (apps with different sign-ins): a message to one reaches both. Needs a CLI login; a deployed App gets CONSOLE_ONLY
inbox(user_id, *, limit=50)List[Dict]A user's recent notifications, one per message, for an in-app inbox
report(delivery_id, event='opened')DictReport received, opened or the message's conversion_event (e.g. after a browser click)
user_room(user_id)strThe room an open app joins to get the user's notifications live (also exported from hikigai.appsdk)
from hikigai.appsdk import AppClient

client = AppClient()

# Publish to a topic the console allowed this App on
client.notifications.publish(
    topic="lab-results",
    title="Your result is ready, {{ first_name | there }}",
    body="Open the app to see it.",
    users=["patient-123"],               # leave out to reach every subscriber
    data={"screen": "results", "id": "456"},
    options={"private": True},           # keep health details off the lock screen
    idempotency_key="result-456",        # retries never send twice
)

# Every day at 20:00 in each user's own time zone
client.notifications.schedule(
    message={"topic": "reminders", "title": "Time to log your blood sugar"},
    kind="recurring",
    recurrence={"frequency": "daily", "time": "20:00"},
    timezone_mode="user_local",
)

# Your web app's backend: register the browser the page subscribed
client.notifications.register_browser(subscription=subscription_json, user_id=user.id, topics=["lab-results"])

client.notifications.subscribe("lab-results", user_id="patient-123")
client.notifications.set_user_properties("patient-123", {"first_name": "Pat", "plan": "premium"})
client.notifications.link_users("portal-881", "patient-123")

items = client.notifications.inbox("patient-123")
client.notifications.report(items[0]["delivery_id"], "opened")
room = client.notifications.user_room("patient-123")   # join it to get new messages live

options: sound, badge, priority, android_channel, ttl_seconds (default 7 days), collapse_key, private, private_title, and for browsers url and icon. An app that should receive every message on a topic adds a webhook on the topic in the console and checks each call with parse_webhook_event (body type is notification.published). All routes: API Reference → Notifications.

Storage

Access via client.storage. Platform-managed object storage scoped to project + app_id — PDFs, images, audio, and other app outputs. Same client as AgentSDK.

Methods

MethodReturnsDescription
upload(app_id, file, filename, content_type=..., metadata=None, ttl=None)StorageUploadResultMultipart upload; optional metadata + object TTL. Includes signed_url on success.
signed_url(app_id, object_id, ttl=3600)SignedUrlResultMint a temporary download URL
list(app_id, content_type=None, status='active', limit=20, page=1)StorageListResultPaginated list with filters
get(app_id, object_id)StorageObjectInfoFetch object metadata
delete(app_id, object_id)NoneDelete an object
with open("audio.wav", "rb") as f:
    uploaded = client.storage.upload(
        app_id="app_123",
        file=f,
        filename="audio.wav",
        content_type="audio/wav",
        metadata={"session": "s-9"},
        ttl=86400,
    )

url = client.storage.signed_url("app_123", uploaded.object_id, ttl=3600)
print(url.signed_url, url.expires_at)

info = client.storage.get("app_123", uploaded.object_id)
print(info.original_filename, info.size_bytes, info.metadata)

page = client.storage.list("app_123", content_type="audio/wav", status="active", limit=20, page=1)
for obj in page.objects:
    print(obj.object_id, obj.original_filename)
print(page.total, page.total_pages)

client.storage.delete("app_123", uploaded.object_id)

SONA Personalization

Access via client.sona. Invoke with plugin_context={"sona": {"user_id": "..."}}to receive SONA metadata on response.plugins.

response = agent.invoke(
    "Draft discharge summary",
    plugin_context={"sona": {"user_id": "dr-smith-uuid"}},
)
output_id = response.plugins["sona"]["output_id"]

client.sona.submit_edit(output_id, "User-edited note text...")
client.sona.approve_output(output_id, user_id="dr-smith-uuid")
prefs = client.sona.get_preferences("dr-smith-uuid", agent_id=agent.id)
suggestions = client.sona.get_suggestions("dr-smith-uuid")

End-User Identity

Add signup, login, MFA, QR badge login, and SSO for your app's end users — clinicians, patients, staff. Each app is backed by a dedicated AWS Cognito user pool the platform provisions for you; login returns standard OIDC tokens. Everything is reached through client.identity.

class IdentityClient

client.identityCore

End-user authentication and account management for the app's Cognito pool, plus QR/PIN badge credentials. Access it as a property on AppClient.

Account & auth methods

MethodReturnsDescription
signup(app_id, email, password, first_name=None, last_name=None, role=None, attributes=None, metadata=None)dictRegister a new end user. attributes = Cognito fields (e.g. phone_number); metadata = opaque JSON as custom:metadata.
confirm(app_id, email, code)dictConfirm a signup with the emailed code
login(app_id, email, password)dictAuthenticate — returns OIDC tokens or an MFA challenge
refresh(app_id, refresh_token)dictExchange a refresh token for fresh tokens
logout(app_id, email)dictGlobally sign the user out
forgot_password(app_id, email)dictRequest a password-reset code (emailed by Cognito)
reset_password(app_id, email, code, new_password)dictSet a new password with the emailed code
change_password(app_id, access_token, current_password, new_password)dictChange password for a logged-in user
create_user(app_id, email, password, first_name, last_name, role=None, metadata=None)dictSame as signup — creates the Cognito/GCP user
get_user(app_id, email)dictFetch Cognito profile (requires app_id)
list_users(app_id, limit=50, offset=0)list[dict]List users in the app's pool
update_user(app_id, email, **fields)dictUpdate Cognito profile (role, name, metadata, is_active, phone_number). Email cannot be changed.
list_app_users(app_id, limit=50, offset=0)list[dict]List the app's end users
delete_app_user(app_id, email)NoneDelete a user from the pool
verify_qr(app_id, qr_payload)VerifiedUserVerify an HKG2 QR badge against the app pool
verify_pin(app_id, email, pin)VerifiedUserVerify PIN stored on Cognito
verify_sso(app_id, token)VerifiedUserVerify SSO id token for the app pool
update_own_user_data(app_id, token, user_data)VerifiedUserThe signed-in user (from their ID token) updates their own metadata.user_data. Keys are set, None removes a key; other metadata stays admin-only.
set_own_secret(app_id, token, name, value, expires_in_seconds=3600)dictKeep a short-lived private value for the signed-in user (encrypted on their Cognito record, 60 s to 1 day). Returns name + expires_at.
get_own_secret(app_id, token, name)dict | NoneThe signed-in user's value (name, value, expires_at), or None when missing or expired
delete_own_secret(app_id, token, name)dictRemove the signed-in user's value (no error when missing)
issue_qr(app_id, email)dictIssue Cognito QR badge (same as issue_qr_login)
issue_pin(app_id, email, pin)dictSet PIN on the Cognito user

MFA, QR & SSO

MethodReturnsDescription
mfa_associate(app_id, access_token)dictBegin TOTP enrollment — returns secret for a QR code
mfa_verify(app_id, access_token, code, device_name=None)dictVerify the first code to finish enrollment
mfa_set_preference(app_id, access_token, enabled=True)dictTurn TOTP MFA on or off
mfa_respond(app_id, email, session, code)dictComplete a login that returned an MFA challenge
issue_qr_login(app_id, email)dictIssue a QR badge credential for a user
qr_login(app_id, qr_payload)dictExchange a scanned QR payload for tokens
configure_sso(app_id, provider_name, provider_type, …)dictAdd a Google/Okta/SAML/OIDC provider
sso_authorize_url(app_id, redirect_uri, provider=None)dictBuild the hosted-UI authorize URL
sso_exchange(app_id, code, redirect_uri)dictExchange the callback code for tokens

Setup (one-time, per app)

enable_identity(app_id, mode='managed', enabled_methods=…)dictProvision the app's Cognito pool
get_identity_config(app_id)dictGet config + provisioning status
byo_setup()dictCloudFormation params for bring-your-own Cognito
byo_test(role_arn, region=None)dictVerify a cross-account role before enabling BYO

Sign up, confirm, log in

attributes are Cognito profile fields (string values — e.g. phone_number in E.164). metadata is opaque app JSON stored as Cognito custom:metadata (GCP BYO uses custom claims). They are not interchangeable. Cognito/GCP is the source of truth — there is no separate EndUser DB index for profile data.

from hikigai.appsdk import AppClient

client = AppClient()  # inside the deployed App

# 1. Register the end user
client.identity.signup(
    app_id="app_123",
    email="clinician@hospital.com",
    password="Temp#Pass2026",
    first_name="Asha",
    last_name="Mehta",
    role="clinician",
    # attributes → Cognito fields (strings only; e.g. phone_number in E.164)
    attributes={"phone_number": "+14155552671"},
    # metadata → Cognito custom:metadata JSON
    metadata={"doctorID": "6278383837"},
)

# 2. Confirm (skip if the pool auto-confirms)
client.identity.confirm("app_123", "clinician@hospital.com", code="123456")

# 3. Log in -> OIDC tokens
tokens = client.identity.login("app_123", "clinician@hospital.com", "Temp#Pass2026")
print(tokens["access_token"])

# 4. Refresh later
fresh = client.identity.refresh("app_123", tokens["refresh_token"])

Forgot password

# 1. Request reset code (Cognito emails it)
client.identity.forgot_password("app_123", "clinician@hospital.com")

# 2. User enters code + new password
client.identity.reset_password(
    "app_123", "clinician@hospital.com", code="123456", new_password="NewTemp#Pass2026"
)

Change password (logged in)

tokens = client.identity.login("app_123", "clinician@hospital.com", "Temp#Pass2026")
client.identity.change_password(
    "app_123",
    access_token=tokens["access_token"],
    current_password="Temp#Pass2026",
    new_password="NewTemp#Pass2026",
)

Update role / profile

# app_id + email required (Cognito is source of truth)
client.identity.update_user(
    "app_123", "clinician@hospital.com",
    role="doctor", first_name="Asha", last_name="Mehta",
)

Multi-factor login

# Login may return an MFA challenge instead of tokens
result = client.identity.login("app_123", "clinician@hospital.com", "Temp#Pass2026")

if result.get("status") == "challenge":
    code = input("Enter your authenticator code: ")
    tokens = client.identity.mfa_respond(
        app_id="app_123",
        email="clinician@hospital.com",
        session=result["session"],
        code=code,
    )
    print(tokens["access_token"])

QR badge login

# Admin: issue a badge for the user (HKG2 payload shown once)
badge = client.identity.issue_qr_login("app_123", "clinician@hospital.com")
print(badge["qr_payload"])   # encode into the printed badge

# Kiosk: scan the badge, exchange it for tokens
tokens = client.identity.qr_login("app_123", scanned_payload)

# Or verify without minting tokens (runtime check)
user = client.identity.verify_qr("app_123", scanned_payload)
print(user.first_name, user.role)

The signed-in user's own data

Pass the user's ID token as token; the platform always acts on the user the token belongs to, so a user can only change themselves. Only metadata.user_data can be changed this way (at most 50 keys per call; the whole metadata stays within 2048 characters). Own secrets are kept encrypted on the user's own Cognito record (never in metadata or tokens; the console shows names and expiry only) and readable only by the same user of the same app until they expire (60 s to 1 day; all of one user's values together roughly 1,400 characters; not for GCP Identity Platform user lists).

id_token = tokens["id_token"]

# Update the user's own details (None removes a key)
user = client.identity.update_own_user_data(
    "app_123", id_token, {"preferences": {"units": "metric"}, "old_key": None}
)
print(user.metadata["user_data"])

# Keep a short-lived private value, e.g. a session with another service
client.identity.set_own_secret("app_123", id_token, "partner.session", session_json, expires_in_seconds=1800)
saved = client.identity.get_own_secret("app_123", id_token, "partner.session")  # None when missing or expired
client.identity.delete_own_secret("app_123", id_token, "partner.session")
signup / create_user

Use identity.signup() (or create_user, which calls the same path) for Cognito/GCP accounts. Profile, QR, and PIN all live on the IdP — pass app_id on management and verify calls. Prefer email over legacy platform UUIDs.

Identity Verification (CLEAR, ID.me)

client.identity_verification proves who a patient is with CLEAR or ID.me, using your own vendor credentials. Start a session, send the patient to verification_url, then read the result (or react to the identity.verification_completed event). Full routes: API reference → Identity Verification.

iv = client.identity_verification

# once per project (manage scope)
iv.configure_provider("idme", client_id="...", client_secret="...",
                      allowed_return_urls=["https://app.example.com/verified"])

session = iv.start("idme", patient_reference="fhir-Patient-123",
                   return_url="https://app.example.com/verified")
redirect_to(session.verification_url)

done = iv.wait(session.session_id)            # polls until verified / failed / expired / cancelled
if done.verified:
    ok = iv.match(done.session_id, first_name="Asha", last_name="Mehta", date_of_birth="1984-02-29")

iv.patient_status("fhir-Patient-123")         # latest verified session for a patient

Also: list_providers, delete_provider, test_provider, get, list, complete (your own redirect_uri), cancel, link, end_user_status.

Complete Examples

Basic Agent Invocation

from hikigai.appsdk import AppClient

client = AppClient()

# Get agent
agent = client.agent("customer-support")

# Invoke
response = agent.invoke("How do I reset my password?")
print(response.content)
print(f"Latency: {response.metadata.latency_ms}ms")

Streaming Responses

agent = client.agent("content-writer")

# Stream in real-time
print("Agent response: ", end="")
for chunk in agent.stream("Write a paragraph about AI"):
    print(chunk, end="", flush=True)
print()  # New line

Session-Based Chat Application

Run this inside your deployed App (for example as a server endpoint); run locally it fails with DEPLOY_KEY_REQUIRED.

import uuid
from hikigai.appsdk import AppClient

def chat_session(user_id: str):
    """Start a chat session for a user."""
    client = AppClient()
    agent = client.agent("chatbot")
    
    # Create session-bound agent
    session = agent.with_session(user_id)
    
    print("Chat started. Type 'exit' to quit.")
    
    while True:
        user_input = input("You: ")
        if user_input.lower() == "exit":
            break
        
        # Invoke with session context
        response = session.invoke(user_input)
        print(f"Bot: {response.content}")

# Start chat for a user
chat_session(f"user-{uuid.uuid4()}")

Listing and Filtering Agents

client = AppClient()

# List all agents
agents = client.list_agents()
for agent in agents:
    print(f"{agent.name} (v{agent.version}): {agent.status}")

# Filter by category
medical_agents = client.list_agents(category="Medical Coding")

# Search
search_results = client.list_agents(search="diagnosis")

Error Handling

from hikigai.appsdk import (
    AppClient,
    AgentNotFoundError,
    InvocationError,
    RateLimitError
)

client = AppClient()

try:
    agent = client.agent("my-agent")
    response = agent.invoke("Hello")
    print(response.content)
    
except AgentNotFoundError:
    print("Agent not found. Check the agent ID.")
    
except InvocationError as e:
    print(f"Invocation failed: {e}")
    
except RateLimitError:
    print("Rate limit exceeded. Please wait.")
    
except Exception as e:
    print(f"Unexpected error: {e}")

Error Handling

AgentNotFoundError

Raised when the requested agent doesn't exist

from hikigai.appsdk import AgentNotFoundError

try:
    agent = client.agent("nonexistent-agent")
except AgentNotFoundError as e:
    print(f"Agent not found: {e}")

InvocationError

Raised when agent invocation fails

from hikigai.appsdk import InvocationError

try:
    response = agent.invoke("Complex query...")
except InvocationError as e:
    print(f"Invocation failed: {e}")

AuthenticationError

Raised when the credential is invalid or missing, or when a runtime call is made outside a deployed App. Structured platform errors carry a code such as DEPLOY_KEY_REQUIRED, INVALID_KEY, KEY_PROJECT_MISMATCH, APP_DEPLOY_REQUIRED, APP_STOPPED or REQUIRES_ATTESTATION.

from hikigai.appsdk import AuthenticationError, ConfigurationError

try:
    client = AppClient()                         # not signed in -> ConfigurationError
    client.agent("medical-coder").invoke("...")  # login ended -> AuthenticationError
except (AuthenticationError, ConfigurationError) as e:
    print(f"Auth/config failed: {e}")   # "Not signed in. On your computer run `hikigai login` ..."
    print(getattr(e, "code", None))     # e.g. CLI_SESSION_INVALID

RateLimitError

Raised when API rate limit is exceeded

from hikigai.appsdk import RateLimitError
import time

try:
    response = agent.invoke("Query")
except RateLimitError as e:
    print(f"Rate limit hit. Retry after: {e.retry_after}s")
    time.sleep(e.retry_after)
    response = agent.invoke("Query")  # Retry