Restate Typescript SDK
    Preparing search index...

    Type Alias ServiceOptions

    type ServiceOptions = {
        abortTimeout?: Duration | number;
        asTerminalError?: (error: any) => TerminalError | undefined;
        idempotencyRetention?: Duration | number;
        inactivityTimeout?: Duration | number;
        ingressPrivate?: boolean;
        journalRetention?: Duration | number;
        retryPolicy?: RetryPolicy;
    }
    Index

    Properties

    abortTimeout?: Duration | number

    Guards against invocations that fail to terminate after inactivity. The abort timeout starts after inactivityTimeout expires and a graceful termination was requested. When this timer expires, the invocation is aborted.

    This timer may interrupt user code. If more time is needed for graceful termination, increase this value.

    Overrides the default abort timeout configured in the Restate server for invocations to this service.

    Note: Available only when registering this endpoint with restate-server v1.4 or newer; otherwise service discovery will fail.

    asTerminalError?: (error: any) => TerminalError | undefined

    By default, Restate treats errors as terminal (non-retryable) only when they are instances of TerminalError.

    Use this hook to map domain-specific errors to TerminalError (or return undefined to keep them retryable). When mapped to TerminalError, the error will not be retried.

    Note: This applies to errors thrown inside ctx.run closures as well as errors thrown by Restate handlers.

    Example:

    class MyValidationError extends Error {}

    const greeter = restate.service({
    name: "greeter",
    handlers: {
    greet: async (ctx: restate.Context, name: string) => {
    if (name.length === 0) {
    throw new MyValidationError("Length too short");
    }
    return `Hello ${name}`;
    }
    },
    options: {
    asTerminalError: (err) => {
    if (err instanceof MyValidationError) {
    // My validation error is terminal
    return new restate.TerminalError(err.message, { errorCode: 400 });
    }

    // Any other error is retryable
    }
    }
    });
    idempotencyRetention?: Duration | number

    The retention duration of idempotent requests to this service.

    Note: Available only when registering this endpoint with restate-server v1.4 or newer; otherwise service discovery will fail.

    inactivityTimeout?: Duration | number

    Guards against stalled invocations. Once this timeout expires, Restate requests a graceful suspension of the invocation (preserving intermediate progress).

    If the invocation does not react to the suspension request, abortTimeout is used to abort it.

    Overrides the default inactivity timeout configured in the Restate server for all invocations to this service.

    Note: Available only when registering this endpoint with restate-server v1.4 or newer; otherwise service discovery will fail.

    ingressPrivate?: boolean

    When set to true, this service (and all its handlers) cannot be invoked via the Restate server HTTP or Kafka ingress; it can only be called from other services.

    Note: Available only when registering this endpoint with restate-server v1.4 or newer; otherwise service discovery will fail.

    journalRetention?: Duration | number

    Journal retention applied to all requests to all handlers of this service.

    When a request includes an idempotency key, idempotencyRetention caps the journal retention time.

    Note: Available only when registering this endpoint with restate-server v1.4 or newer; otherwise service discovery will fail.

    retryPolicy?: RetryPolicy

    Retry policy to apply to all requests to this service. For each unspecified field, the default value configured in the restate-server configuration file will be applied instead.