Skip to content

Getting Started

A service is a program that connects to Requence, receives messages, processes them, and returns results. Services are the building blocks of every task template.

Before writing any code, create the service in the Requence UI. Define its input schema, configuration schema, and outputs — including an output schema for each. Requence uses these definitions to validate data at design time and route messages at execution time.

Terminal window
npm install @requence/service

Every service needs an access token to connect to Requence. In the services list view, click the Copy credentials button to copy the access token to your clipboard.

The token is resolved in this order:

  1. accessToken option passed to createService()
  2. REQUENCE_SERVICE_ACCESS_TOKEN or REQUENCE_ACCESS_TOKEN environment variable
  3. requence.service.accessToken or requence.accessToken in package.json
Terminal window
REQUENCE_SERVICE_ACCESS_TOKEN=your-token bun run index.ts
import { createService } from '@requence/service'
createService('1.0.0', (ctx) => {
const input = ctx.input
return { message: `Hello, ${input.name}!` }
})

That’s it. When Requence dispatches a message to this service, the handler runs and the return value is sent back as the service’s result.

Learn about the full Context API available inside your message handler.