Skip to content

Give your agent a number

A real iMessage line that customers save like any contact. Your model and code stay where they run: each text reaches your app, and Keiki delivers the reply.

app/api/keiki/route.ts
import { createTurnClient, verifyKeikiDispatch } from '@onkeiki/channels'

export async function POST(req: Request) {
  const request = await verifyKeikiDispatch(
    { rawBody: await req.text(), headers: req.headers },
    { signingSecret: process.env.KEIKI_SIGNING_SECRET! },
  )
  if (request.kind !== 'turn') return new Response(null, { status: 204 })

  const { turn, turnToken } = request
  const { turnUrl } = turn.keiki
  const keiki = createTurnClient({ turnUrl, turnToken })

  await keiki.message(await yourAgent(turn.messages), {
    idempotencyKey: turn.turnId,
  })
  await keiki.complete({ status: 'completed' })

  return new Response(null, { status: 202 })
}

Start from your stack

Bring the loop you already have, or call your Keiki agent from the SDK you already use.

tools/find-order.ts
import { Effect, Schema } from 'effect'
import { defineTool } from '@onkeiki/agents'
import { orders } from './store'

export const findOrder = defineTool({
  name: 'find_order',
  description: 'Look up a customer order.',
  input: Schema.Struct({ id: Schema.String }),
  execute: ({ id }) =>
    Effect.promise(() => orders.get(id)),
})

Everything else you’ll need

Text your agent today.

Connect your app, give it a line, and send it the first message yourself.