@hikigai/agent-sdk
Agent SDK
Official Node.js SDK for deploying and managing healthcare AI agents on Hikigai. Full type safety with Zod validation and modern async/await patterns.
Installation
Choose your preferred package manager:
npm
npm install @hikigai/agent-sdkyarn
yarn add @hikigai/agent-sdkpnpm
pnpm add @hikigai/agent-sdkSign in on your computer
To run your code on your computer, sign in once with your Hikigai account. There is no key to copy. The command comes with @hikigai/agent-sdk (run it with npx, or install the package globally to type just hikigai).
npx @hikigai/agent-sdk login # opens the browser: pick the project, check the code, Approve
npx @hikigai/agent-sdk login --project <id> # or name the project hereYou 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 new AgentClient() 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.
npx @hikigai/agent-sdk whoami # who, which project, time left
npx @hikigai/agent-sdk token # print the token (curl / Postman: Authorization: Bearer <token>)
npx @hikigai/agent-sdk 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
- On your computer: run
npx @hikigai/agent-sdk loginonce (seeSign in on your computer). Thennew AgentClient()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_IDandHIKIGAI_PLATFORM_URL. The SDK swaps the key for a 5-minute token atPOST /api/v1/auth/exchangeand 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 { AgentClient, InputSchema, OutputSchema } from '@hikigai/agent-sdk'
// On your computer, after `npx @hikigai/agent-sdk login`: no options needed
// (your role in the project must allow deploying).
const client = new AgentClient()
const agent = await client.deploy({
name: 'medical-coder',
displayName: 'Medical Coding Assistant',
description: 'Extracts ICD-10 and CPT codes from clinical notes',
instruction: 'You are a medical coding expert. Extract ICD-10 and CPT codes.',
model: 'claude-sonnet-5-5',
category: 'coding-billing',
version: '1.0.0',
inputSchema: new InputSchema({
clinical_note: { type: 'string', required: true },
}),
outputSchema: new OutputSchema({
icd_codes: { type: 'array', items: { type: 'string' } },
cpt_codes: { type: 'array', items: { type: 'string' } },
}),
})
console.log(`Deployed: ${agent.id} (${agent.slug})`)
// Redeploying the same agent needs a higher version, or the platform returns 409:
// await client.deploy({ ...config, version: '1.0.1' })
// await client.updateAgent(agent.id, { instruction: '...', version: '1.0.2' })
// (deployFromFile() is retired — the platform returns 410; use deploy().)
// Invoking is a runtime call: it only works from inside a deployed App.
// In your deployed App: const agent = await new AppClient().agent(slug); await agent.invoke({...})Core Concepts
AgentClient
Main interface for agent deployment and management.
class AgentClient {
constructor(options?: {
apiKey?: string // Usually omitted: HIKIGAI_API_KEY in a deployed App, else your hikigai login.
// Inside a deployed App leave unset: the platform sets it
projectId?: string // Project ID (or HIKIGAI_PROJECT_ID env var)
baseUrl?: string // API endpoint
timeout?: number // Request timeout in milliseconds
})
readonly jobs: JobsClient
readonly storage: StorageClient
readonly events: EventsClient
readonly identityVerification: IdentityVerificationClient
deploy(config: AgentConfigInput, options?: {
timeout?: number
pollInterval?: number
cloudService?: string // optional; omit to use org default
region?: string
cloudCredentialId?: string
cloudCredentialName?: string // Cloud accounts name; omit for org default
}): Promise<DeployedAgent>
listAgents(): Promise<DeployedAgent[]>
getAgent(agentId: string): Promise<DeployedAgent>
updateAgent(agentId: string, update: Record<string, unknown>): Promise<DeployedAgent>
deleteAgent(agentId: string): Promise<void>
invoke(agentId: string, input: string | Record<string, unknown>, options?: {
sessionId?: string; provider?: string; model?: string
}): Promise<Record<string, unknown>>
stream(agentId: string, input: string | Record<string, unknown>, options?: {
sessionId?: string; provider?: string; model?: string
}): AsyncIterable<string>
getAuthToken(): Promise<AuthTokenResponse>
close(): void
}Jobs (client.jobs)
Background job queue for long-running agent work. Methods: enqueue, get, list, cancel, replay, wait, stream.
// runtime: inside a deployed App
const job = await client.jobs.enqueue('agent.invoke', {
input: 'Batch-code these notes',
}, { agentId: agent.id, priority: 'standard' })
const detail = await client.jobs.wait(job.id)
console.log(detail.status, detail.result)
// Also available:
// await client.jobs.get(job.id)
// await client.jobs.list({ status: 'failed', page: 1 })
// await client.jobs.cancel(job.id)
// await client.jobs.replay(job.id)
// for await (const event of client.jobs.stream(job.id)) { ... }Storage (client.storage)
Platform object storage scoped to project + appId. Methods: upload, signedUrl, list, get, delete.
const uploaded = await client.storage.upload('app_123', fileBuffer, 'note.pdf', {
contentType: 'application/pdf',
metadata: { visitId: 'v-42' },
ttl: 86400, // optional object TTL (seconds)
})
console.log(uploaded.objectId, uploaded.sizeBytes, uploaded.signedUrl)
const { signedUrl, expiresAt } = await client.storage.signedUrl(
'app_123',
uploaded.objectId,
3600,
)
const info = await client.storage.get('app_123', uploaded.objectId)
console.log(info.originalFilename, info.metadata, info.status)
const page = await client.storage.list('app_123', {
contentType: 'application/pdf',
status: 'active',
limit: 20,
page: 1,
})
for (const obj of page.objects) {
console.log(obj.objectId, obj.originalFilename, obj.sizeBytes)
}
console.log(page.total, page.totalPages)
await client.storage.delete('app_123', uploaded.objectId)Rooms & WebRTC
SFU (recommended for A/V + in-call text): connectMedia mints a media token + ICE servers. Then WHIP-join the SFU — no rooms WebSocket needed for media or DataChannel chat. RoomSession: WebSocket pub/sub for app events.
import { connectMedia, RoomSession } from '@hikigai/agent-sdk'
// Inside the deployed App: HIKIGAI_API_KEY (Deploy key) / HIKIGAI_PROJECT_ID are set by the platform
// --- SFU A/V + DataChannel chat (HTTP) ---
const media = await connectMedia({
baseUrl: process.env.HIKIGAI_PLATFORM_URL ?? 'https://backend.hikigaiplatform.io',
apiKey: process.env.HIKIGAI_API_KEY!,
projectId: process.env.HIKIGAI_PROJECT_ID!,
room: 'support-call-123',
agentId: 'agent_support', // optional
// iceServers: [...] // optional bring-your-own for this token
})
console.log(media.token, media.sfu_url, media.ice_servers, media.turn_source)
// sfu_url is platform-provided — POST offer to `${media.sfu_url}/rooms/${room}/join` (don't hardcode)
// --- WebSocket rooms ---
const room = new RoomSession({
baseUrl: process.env.HIKIGAI_PLATFORM_URL ?? 'https://backend.hikigaiplatform.io',
})
await room.connect()
await room.join('rounds-42')
await room.publish('rounds-42', 'update', { status: 'in_progress' })
for await (const frame of room) {
if (frame.type === 'message') console.log(frame.event, frame.data, frame.seq)
if (frame.type === 'error') break
}
await room.close()TURN: Hikigai-managed by default, or Organization settings → WebRTC TURN (BYO), or iceServers on connectMedia. See API → WebRTC · TURN.
Configuration
AgentConfig
Comprehensive configuration for agent deployment (Zod-validated).
interface AgentConfig {
// Identity
name: string // 3-64 chars, lowercase, hyphens only
displayName: string // 3-100 chars
description: string // 10-500 chars
longDescription?: string
// Core
agentType?: 'llm' | 'sequential' | 'parallel' | 'loop' // Default: 'llm'
instruction: string
model: string // Default: 'gemini-3.8-flash'
// Schemas
inputSchema: InputSchema | Record<string, unknown>
outputSchema: OutputSchema | Record<string, unknown>
// Modality
inputModality?: string // text | audio | combinations
outputModality?: string
vad?: VadConfig // Live automatic VAD (audio input only)
// Tools & connectors (root connectors → every Sequential/Parallel/Loop leaf)
tools?: unknown[]
connectors?: ConnectorConfig[] // see #mcp-subagents
subAgents?: SubAgentConfig[]
// Runtime
timeout?: number // Default: 60
memoryMb?: number // Default: 512
minInstances?: number // Default: 1 (always warm); 0 scales to zero (cold start after idle)
maxInstances?: number // Default: 2
// Omit cloudProvider to use Organization settings → Cloud accounts (deploy default)
cloudProvider?: string // 'gcp' | 'aws'
// Versioning & compliance
version: string
changelog?: string
hipaaCompliant?: boolean // Default: true
category?: string
tags?: string[]
}VadConfig
Automatic voice activity detection for live audio agents. Pass when inputModality includes audio. Defaults: 800 ms / low / low. Include VAD on every same-name deploy() to preserve or change it.
interface VadConfig {
silenceDurationMs?: number // 200–2000, default 800
endOfSpeechSensitivity?: 'high' | 'low' // default 'low'
startOfSpeechSensitivity?: 'high' | 'low' // default 'low'
}
await client.deploy({
...,
inputModality: 'audio',
outputModality: 'text',
vad: {
silenceDurationMs: 800,
endOfSpeechSensitivity: 'low',
startOfSpeechSensitivity: 'low',
},
})Input / Output Schemas
Field types: string, integer, number, boolean, array, object. Optional description, required, enum, items, properties.
import { InputSchema, OutputSchema } from '@hikigai/agent-sdk'
const inputSchema = new InputSchema({
patient_id: { type: 'string', required: true },
age: { type: 'integer', required: true, minimum: 0, maximum: 150 },
symptoms: { type: 'array', items: { type: 'string' } },
})
const outputSchema = new OutputSchema({
diagnosis: { type: 'string' },
confidence: { type: 'integer', minimum: 0, maximum: 100 },
recommendations: { type: 'array', items: { type: 'string' } },
})Workflow Agents (Sequential / Parallel / Loop)
Set agentType to 'sequential', 'parallel', or 'loop' with nested subAgents. Text workflows advance on their own. Live pipelines need liveHandoff on leaves. Open live sessions with AppSDK live().
| Type | Behavior | liveHandoff |
|---|---|---|
sequential | Leaves one after another | Per-leaf task_completed or after_output |
parallel | Concurrent branches (mic teed) | Same; prefer text-only outs |
loop | Repeat until escalate / maxIterations | Same as sequential |
SubAgentConfig
One leaf (or nested workflow) under a Sequential / Parallel / Loop root.
interface SubAgentConfig {
name: string
agentType?: 'llm' | 'sequential' | 'parallel' | 'loop'
model?: string
instruction?: string
description?: string
tools?: string[]
inputModality?: string // default 'text'
outputModality?: string // default 'text'
liveHandoff?: 'task_completed' | 'after_output' // default 'task_completed'
subAgents?: SubAgentConfig[] // nested workflows
maxIterations?: number // loop only
source?: 'marketplace' // reuse marketplace agent
sourceAgentId?: string
}liveHandoff: task_completed (default, multi-turn) or after_output (one-shot after model reply). Ignored for simple live LlmAgent roots.
await client.deploy({
name: 'clinical-live-pipeline',
displayName: 'Clinical Live Pipeline',
description: 'Sequential live intake with one-shot leaves',
agentType: 'sequential',
model: 'gemini-3.8-live',
instruction: 'Orchestrate the live clinical pipeline.',
version: '1.0.0',
inputModality: 'audio',
outputModality: 'audio',
inputSchema: { type: 'object', properties: { audio: { type: 'string' } } },
outputSchema: { type: 'object', properties: { note: { type: 'string' } } },
subAgents: [
{
name: 'voice-intake',
model: 'gemini-3.8-live',
instruction: 'Wait for the user, then acknowledge in under 8 words.',
inputModality: 'audio',
outputModality: 'audio',
liveHandoff: 'after_output',
},
{
name: 'note-composer',
model: 'gemini-3.8-live',
instruction: 'Emit a short SOAP note from context, then stop.',
inputModality: 'text',
outputModality: 'text',
liveHandoff: 'after_output',
},
],
})Reuse marketplace agents as sub-agents
Pass instruction / model for your own leaves. Set source: 'marketplace' with the marketplace agent name (or slug) to reuse it — no UUID, instruction, or schemas. The platform hydrates those at deploy time. Optionally pass sourceAgentId instead.
await client.deploy({
name: 'cpt2-note-workflow',
displayName: 'CPT2 Note Workflow',
description: 'Clean a clinical note, then reuse CPT2 from the marketplace',
agentType: 'sequential',
model: 'gemini-3.8-flash',
instruction: 'Pass the note through prep, then CPT Category II extraction.',
version: '1.0.0',
category: 'coding-billing',
inputSchema: { type: 'object', properties: { input: { type: 'string' } }, required: ['input'] },
outputSchema: { type: 'object', properties: { output: { type: 'string' } }, required: ['output'] },
subAgents: [
{
name: 'note_cleaner',
model: 'gemini-3.8-flash',
instruction: 'Clean and structure the note for CPT II coding. Do not invent facts.',
description: 'Prepares notes for coding',
},
{
name: 'cpt2_code_agent', // marketplace name or slug
source: 'marketplace',
},
],
})
// Invoke with App SDK: client.agent('cpt2-note-workflow').invoke({ input: '...' })MCP on Sub-Agents
Declare connectors on the root agent config. They serialize as mcp_connectors and at invoke/live attach to every LlmAgent leaf (Sequential / Parallel / Loop) — not only a simple LLM root. Prefer declaring at deploy so leaf outputSchema is not baked (ADK skips CallTool when schema is set).
await client.deploy({
name: 'vitals-fetch-subagent',
displayName: 'Vitals Fetch (Subagent MCP)',
description: 'Sequential: MCP fetch leaf, then summarizer',
instruction: 'Run fetcher then summarizer. Do not answer yourself.',
model: 'gemini-3.8-flash',
agentType: 'sequential',
category: 'monitoring',
version: '1.0.0',
// Root connectors → every leaf can CallTool
connectors: [
{
slug: 'idexx-mcp-server',
toolFilter: ['get_vitals_for_today'],
required: true,
},
],
subAgents: [
{
name: 'vitals-fetcher',
model: 'gemini-3.8-flash',
instruction: 'Call get_vitals_for_today once with site_id and patient_id.',
},
{
name: 'vitals-summarizer',
model: 'gemini-3.8-flash',
instruction: 'Emit {"response": "<summary>"}. Do not call tools.',
},
],
inputSchema: /* site_id, patient_id */,
outputSchema: /* response */,
})
// Invoke with AppSDK — see /docs/sdk/node-appsdk#mcp-workflow-agentsTools
Add tools to your agents: functions, OpenAPI specs, MCP, or built-ins.
Function Tools
import { tool } from '@hikigai/agent-sdk'
const searchDatabase = tool(function searchDatabase(query: string): string {
return JSON.stringify(results)
})
await client.deploy({
// ...
tools: [searchDatabase],
})OpenAPI Tools
import { OpenAPITool } from '@hikigai/agent-sdk'
const weatherApi = new OpenAPITool({
specUrl: 'https://api.weather.com/openapi.json',
operationId: 'getCurrentWeather',
})MCP Tools
Static MCPTool entries, or prefer root connectors for project MCP (see MCP on Sub-Agents).
import { MCPTool } from '@hikigai/agent-sdk'
const ehrLookup = new MCPTool('my-ehr-connector', 'get_patient')
// or: new MCPTool({ serverName: 'my-ehr-connector', toolName: 'get_patient' })Built-in Tools
await client.deploy({
// ...
tools: ['web_search', 'execute_code', 'read_file'],
})DeployedAgent
interface DeployedAgent {
id: string
name: string
slug: string
version: string
displayName?: string
description?: string
deploymentStatus: 'active' | 'pending' | 'error'
deploymentType: 'config_based' | 'adk' | 'file'
endpointUrl?: string
cloudProvider?: string
region?: string
hipaaCompliant: boolean
hipaaVerified: boolean
createdAt?: Date
deployedAt?: Date
}List / Get / Update / Delete
const agents = await client.listAgents()
const agent = await client.getAgent('agent-id-or-slug')
// Every redeploy needs a higher version (ValidationError if missing, ConflictError if not higher)
await client.updateAgent(agent.id, { description: 'Updated description', version: '1.0.1' })
await client.deleteAgent(agent.id)
// In your deployed App: const agent = await new AppClient().agent(slug); await agent.invoke({...})Multi-Cloud Deploy
Whatever you set as the default under Organization settings → Cloud accounts is used when you deploy. Omit cloud options to use that default. Pass cloudProvider: 'gcp' or 'aws' only when you need to override it. Every deploy runs in your own cloud account, personal workspaces included (Project settings → Cloud accounts); with none the deploy is refused — Hikigai's cloud is never used. Team orgs need a default account (or an explicit override). The agent runs on your own model key; a deploy without the key for its model's provider is refused.
// Uses Organization settings → Cloud accounts default
const agent = await client.deploy(config)
// Override provider when needed
await client.deploy({ ...config, cloudProvider: 'aws' })
// Or pick a specific account by name
await client.deploy(config, {
cloudCredentialName: 'my-aws-account',
})Catalog / BYOC validation: Node AppSDK → Multi-Cloud.
Events & Webhooks
client.events — HMAC-signed webhooks (at-least-once) and a live event stream (at-most-once). React to agent.deployed / agent.deleted / job.* instead of polling.
// runtime: inside a deployed App
const sub = await client.events.createWebhook({
url: 'https://ci.example.com/hooks/hikigai',
eventTypes: ['agent.deployed', 'agent.deleted'],
description: 'deploy notifications',
})
console.log(sub.secret) // shown once — store it
// Also: listWebhooks, getWebhook, updateWebhook, deleteWebhook, rotateSecret
const stream = client.events.stream(['job.*', 'agent.deployed'])
await stream.connect()
for await (const event of stream) {
console.log(event.type, event.data)
}
await stream.close()Identity Verification (CLEAR, ID.me)
client.identityVerification proves who a patient is with CLEAR or ID.me, using your own vendor credentials. Full routes: API reference → Identity Verification.
const iv = client.identityVerification
await iv.configureProvider('idme', {
clientId: '...',
clientSecret: '...',
allowedReturnUrls: ['https://app.example.com/verified'],
})
const session = await iv.start('idme', {
patientReference: 'fhir-Patient-123',
returnUrl: 'https://app.example.com/verified',
})
// send the patient to session.verificationUrl
const done = await iv.wait(session.sessionId)
if (done.status === 'verified') {
const m = await iv.match(done.sessionId, { firstName: 'Asha', lastName: 'Mehta', dateOfBirth: '1984-02-29' })
}Also: listProviders, deleteProvider, testProvider, get, list, complete, cancel, link, endUserStatus, patientStatus.
Telemetry
Optional OpenTelemetry spans for your own agent tooling: AgentTraceSpans, withSpan and getOtelTraceHeaders are exported from @hikigai/agent-sdk. Configure the OpenTelemetry SDK in your process; without it the helpers are no-ops. AgentClient emits no spans by itself.
Complete Examples
import {
AgentClient,
InputSchema,
OutputSchema,
tool,
} from '@hikigai/agent-sdk'
const client = new AgentClient()
// Define tools
const searchCodes = tool(function search(q: string) {
return JSON.stringify([{ code: 'E11.9', desc: 'Type 2 diabetes' }])
})
// Deploy agent
const agent = await client.deploy({
name: 'icd-cpt-coder',
displayName: 'ICD-10 & CPT Coder',
description: 'Medical coding assistant',
instruction: 'You are a medical coding expert...',
model: 'claude-sonnet-5-5',
category: 'coding-billing',
version: '1.0.0',
inputSchema: new InputSchema({
clinical_note: { type: 'string', required: true },
}),
outputSchema: new OutputSchema({
icd10_codes: { type: 'array' },
cpt_codes: { type: 'array' },
}),
tools: [searchCodes],
hipaaCompliant: true,
})
console.log(`Deployed: ${agent.slug}`)Error Handling
import {
HikigaiError,
AuthenticationError,
RateLimitError,
ValidationError,
DeploymentError,
} from '@hikigai/agent-sdk'
try {
const agent = await client.deploy(config)
} catch (error) {
if (error instanceof AuthenticationError) {
// error.code: DEPLOY_KEY_REQUIRED (runtime call outside a deployed App),
// INVALID_KEY, APP_STOPPED, REQUIRES_ATTESTATION, ...
console.error('Authentication failed:', error.message)
} else if (error instanceof RateLimitError) {
console.error(`Rate limited. Retry after ${error.retryAfter}ms`)
} else if (error instanceof ValidationError) {
console.error(`Validation error: ${error.message}`)
} else if (error instanceof HikigaiError) {
console.error(`API error: ${error.message}`)
}
}