# Referencing functions
Source: https://www.inngest.com/docs/functions/references

Using [`step.invoke()`](/docs/reference/functions/step-invoke), you can directly call one Inngest function from another and handle the result. You can use this with `referenceFunction` to call Inngest functions located in other apps, or to avoid importing dependencies of functions within the same app.

```ts
// @/inngest/compute.ts
// Create a local reference to a function without importing dependencies
computePi = referenceFunction<typeof computePi>({
  functionId: "compute-pi",
});

// Create a reference to a function in another application
computeSquare = referenceFunction({
  appId: "my-python-app",
  functionId: "compute-square",
  // Schemas are optional, but provide types for your call if specified
  schemas: {
    data: z.object({
      number: z.number(),
    }),
    return: z.object({
      result: z.number(),
    }),
  },
});
```

```ts
// @/inngest/someFn.ts
// import the referenece

// square.result is typed as a number
await step.invoke("compute-square-value", {
  function: computeSquare,
  data: { number: 4 }, // input data is typed, requiring input if it's needed
});
```

## How to use `referenceFunction`

The simplest reference just contains a `functionId`. When used, this will invoke the function with the given ID in the same app that is used to invoke it.

The input and output types are `unknown`.

```ts
await step.invoke("start-process", {
  function: referenceFunction({
    functionId: "some-fn",
  }),
});
```

If referencing a function in a different application, specify an `appId` too:

```ts
await step.invoke("start-process", {
  function: referenceFunction({
    functionId: "some-fn",
    appId: "some-app",
  }),
});
```

You can optionally provide `schemas`, which are a collection of [Standard Schemas](https://standardschema.dev/) used to provide typing to the input and output of the referenced function.

<Callout>
In the future, this will also _validate_ the input and output.
</Callout>

```ts
await step.invoke("start-process", {
  function: referenceFunction({
    functionId: "some-fn",
    appId: "some-app",
    schemas: {
      data: z.object({
        foo: z.string(),
      }),
      return: z.object({
        success: z.boolean(),
      }),
    },
  }),
});
```

Even if functions are within the same app, this can also be used to avoid importing the dependencies of one function into another, which is useful for frameworks like Next.js where edge and serverless logic can be colocated but require different dependencies.

```ts
// import only the type

await step.invoke("start-process", {
  function: referenceFunction<typeof someInngestFn>({
    functionId: "some-fn",
  }),
});
```

## Configuration

<Properties>
     <Property name="functionId" type="string" required>
          The ID of the function to reference. This can be either a local function ID or the ID of a function that exists in another app.

          If the latter, `appId` must also be provided. If `appId` is not provided, the function ID will be assumed to be a local function ID (the app ID of the calling app will be used).
     </Property>
     <Property name="appId" type="string">
          The ID of the app that the function belongs to. This is only required if the function being refenced exists in another app.
     </Property>
     <Property name="schemas" type="object">
          The schemas of the referenced function, providing typing to the input `data` and `return` of invoking the referenced function.

          If not provided and a local function type is not being passed as a generic into `referenceFunction()`, the schemas will be inferred as `unknown`.

          <Properties nested>
               <Property name="data" type="zod">
                    The [Standard Schema](https://standardschema.dev/) to use to provide typing to the `data` payload required by the referenced function.
               </Property>
               <Property name="return" type="zod">
                    The [Standard Schema](https://standardschema.dev/) to use to provide typing to the return value of the referenced function when invoked.
               </Property>
          </Properties>
     </Property>
</Properties>