Skip to main content

Requirements

  • Node.js 18 or higher
  • npm, yarn, or pnpm

Installation

npm install @hatchet-dev/typescript-sdk

Setup

1

Get an API token

Obtain your API token from the Hatchet Cloud dashboard or your self-hosted Hatchet instance.The token is a JWT that embeds your tenant ID and server addresses so the SDK can read them automatically.
2

Set environment variables

Export your token so the SDK picks it up automatically:
export HATCHET_CLIENT_TOKEN="<your-api-token>"
For self-hosted deployments, also set the host and port:
export HATCHET_CLIENT_TOKEN="<your-api-token>"
export HATCHET_CLIENT_HOST_PORT="localhost:7070"
3

Initialize the client

Create a shared client instance to reuse across your application:
hatchet-client.ts
import { HatchetClient } from '@hatchet-dev/typescript-sdk';

export const hatchet = HatchetClient.init();
With HATCHET_CLIENT_TOKEN set, no additional configuration is required.
4

Define and run your first task

import { hatchet } from './hatchet-client';

const greet = hatchet.task({
  name: 'greet',
  fn: async (input: { name: string }) => {
    return { message: `Hello, ${input.name}!` };
  },
});

// Trigger the task and wait for the result
const result = await greet.run({ name: 'World' });
console.log(result.message); // Hello, World!

Environment variable reference

VariableDescriptionDefault
HATCHET_CLIENT_TOKENAPI token (required)
HATCHET_CLIENT_HOST_PORTgRPC server host and portRead from token
HATCHET_CLIENT_NAMESPACENamespace prefix for workflow and event names""
HATCHET_CLIENT_TLS_STRATEGYTLS strategy (tls, mtls, or none)"tls"
The SDK validates that HATCHET_CLIENT_TOKEN is a valid JWT. Tokens from the dashboard start with ey — if you see an error about token format, make sure you are copying the full token value.

Build docs developers (and LLMs) love