Skip to main content

Initialize

import { Verial } from '@verial-ai/sdk'

const verial = new Verial({
  apiKey: process.env.VERIAL_API_KEY!,
})
Full configuration options cover baseUrl, timeout, maxRetries, and request hooks.

Run a Published Benchmark

Create a run against an existing benchmark and poll until it finishes.
const run = await verial.runs.create({ benchmarkId: 'bench_01H...' })

while (true) {
  const latest = await verial.runs.get({ id: run.id })
  if (latest.phase === 'completed' || latest.phase === 'failed') {
    console.log('verdict:', latest.verdict, 'score:', latest.score)
    break
  }
  await new Promise((r) => setTimeout(r, 2000))
}

Author a Benchmark

Build an environment, wire up simulators, create a benchmark, and attach tasks + criteria.
import { SimulatorType } from '@verial-ai/sdk'

const env = await verial.environments.create({ name: 'Test Clinic' })

const fhir = await verial.simulators.create({
  type: SimulatorType.FHIR,
  name: 'Primary EHR',
})
await verial.environments.addSimulator({
  environmentId: env.id,
  simulatorId: fhir.id,
})

const benchmark = await verial.benchmarks.create({
  name: 'Prior Auth Workflow',
  environmentId: env.id,
})

const task = await verial.tasks.create({
  benchmarkId: benchmark.id,
  name: 'Submit prior auth for 72148',
})

await verial.evals.create({
  taskId: task.id,
  type: 'fhir_resource_match',
  config: {
    resource_type: 'ServiceRequest',
    match: { 'code.coding.0.code': '72148' },
  },
})

Provision a Standalone Sandbox

Skip environments and benchmarks when you just need a live simulator instance.
const payer = await verial.simulators.create({
  type: SimulatorType.Payer,
  name: 'RadMD',
  config: { portal: 'radmd' },
})

const sandbox = await verial.sandboxes.create({ simulatorId: payer.id })
const details = await verial.sandboxes.get({ id: sandbox.id })

console.log(details.credentials.portal_url)
console.log(details.credentials.username, details.credentials.password)
See the Web Simulator Quickstart for the full browser-login walkthrough.

Iterate a List

List endpoints return a Page<T> that is async-iterable over every item across every page.
for await (const env of await verial.environments.list()) {
  console.log(env.id, env.name)
}
One page at a time:
let page = await verial.environments.list({ limit: 50 })
do {
  for (const env of page.data) {
    console.log(env.id)
  }
  page = (await page.getNextPage()) ?? page
} while (page.hasNextPage())
More in Pagination.

Observe Every Request

Pass hooks for logging, tracing, or injecting auth on specific routes.
const verial = new Verial({
  apiKey: process.env.VERIAL_API_KEY!,
  hooks: [
    {
      beforeRequest(req) {
        console.log('→', req.method, req.url)
      },
      afterResponse(res, req) {
        console.log('←', res.status, req.url)
      },
      onError(err, req) {
        console.error('✗', req.method, req.url, err.message)
      },
    },
  ],
})

Handle Errors

import { RateLimitError, NotFoundError } from '@verial-ai/sdk'

try {
  await verial.runs.get({ id: 'run_does_not_exist' })
} catch (err) {
  if (err instanceof NotFoundError) {
    // 404
  } else if (err instanceof RateLimitError) {
    console.log('retry after', err.retryAfter, 'seconds')
  } else {
    throw err
  }
}
Full hierarchy in Errors.