Create the Inngest Client

The Inngest client object is used to configure your application, enabling you to create functions and send events.

import { Inngest } from "inngest";

const inngest = new Inngest({
  name: "My application",
});

Configuration

  • Name
    name
    Type
    string
    Required
    required
    Description

    The unique name of your application.

  • Name
    eventKey
    Type
    string
    Required
    optional
    Description

    An Inngest Event Key. Alternatively, set the INNGEST_EVENT_KEY environment variable.

  • Name
    schemas
    Type
    EventSchemas
    Required
    optional
    Version
    v2.0.0+
    Description

    Event payload types. See Defining Event Payload Types.

  • Name
    logger
    Type
    Logger
    Required
    optional
    Version
    v2.0.0+
    Description

    A logger object that provides the following interfaces (.info(), .warn(), .error(), .debug()). Defaults to using console if not provided. See logging guide for more details.

  • Name
    middleware
    Type
    array
    Required
    optional
    Version
    v2.0.0+
    Description

    A stack of middleware to add to the client.

  • Name
    env
    Type
    string
    Required
    optional
    Description

    The environment name. Required only when using Branch Environments.

  • Name
    fetch
    Type
    Fetch API compatible interface
    Required
    optional
    Description

    Override the default fetch implementation. Defaults to the runtime's native Fetch API.

  • Name
    inngestBaseUrl
    Type
    string
    Required
    optional
    Description

    Override the default (https://inn.gs/) base URL for sending events.

We recommend setting the INNGEST_EVENT_KEY as an environment variable over using the eventKey option. As with any secret, it's not a good practice to hard-code the event key in your codebase.

Defining Event Payload Types

You can leverage TypeScript to define your event payload types. When you pass types to the Inngest client, events are fully typed when using them with inngest.send() and inngest.createFunction(). This can more easily alert you to issues with your code during compile time.

Click the toggles on the top left of the code block to see the different methods available!

import { EventSchemas, Inngest } from "inngest";

type AppAccountCreated = {
  name: "app/account.created";
  data: {
    userId: string;
  };
};

type AppSubscriptionStarted = {
  name: "app/subscription.started";
  data: {
    userId: string;
    planId: string;
  };
};

type Events = AppAccountCreated | AppSubscriptionStarted;

export const inngest = new Inngest({
  name: "My App",
  schemas: new EventSchemas().fromUnion<Events>(),
});

Reusing event types
v2.0.0+

You can use the GetEvents<> generic to access the final event types from an Inngest client.

It's recommended to use this instead of directly reusing your event types, as Inngest will add extra properties and internal events such as ts and inngest/function.failed.

import { EventSchemas, Inngest, type GetEvents } from "inngest";

export const inngest = new Inngest({
  name: "Example App",
  schemas: new EventSchemas().fromRecord<{
    "app/user.created": { data: { userId: string } };
  }>(),
});

type Events = GetEvents<typeof inngest>;
type AppUserCreated = Events["app/user.created"];

Best Practices

Share your client across your codebase

Instantiating the Inngest client in a single file and sharing it across your codebase is ideal as you only need a single place to configure your client and define types which can be leveraged anywhere you send events or create functions.

./inngest/client.ts

import { Inngest } from "inngest";

export const inngest = new Inngest({ name: "My App" });

./inngest/myFunction.ts

import { inngest } from "./client";

export default inngest.createFunction(...);