---
title: Deploying Chained OpenAI LLM Calls to Vercel with the Inngest SDK
description: Discover how to deploy chained OpenAI LLMs (GPT-4) to Vercel using Inngest SDK for improved conversational AI, multi-turn interactions, and error correction.
url: /kb/guide/chained-openai-llm-calls-vercel-inngest
canonical_url: "https://vercel.com/kb/guide/chained-openai-llm-calls-vercel-inngest"
published: 2025-11-03
last_updated: 2025-11-10
authors: Steven Tey
related:
  - /docs/integrations/openai
  - /docs/functions/fluid-compute
install_vercel_plugin: npx plugins add vercel/vercel-plugin
---
<!-- docsgraph:related -->
## Related pages

> **For AI agents:** Follow these links to understand how this page connects to the rest of the Vercel ecosystem. For the full cross-link map (inbound, outbound, prerequisites, and semantic neighbors), see the .graph.md link below.

- [LangChain](https://vercel.com/docs/ai-gateway/ecosystem/framework-integrations/langchain?from=related&source_path=%2Fkb%2Fguide%2Fchained-openai-llm-calls-vercel-inngest&source_site=vercel-kb&relationship=related) — Learn how to integrate Vercel AI Gateway with LangChain to access multiple AI models through a unified interface
- [Ecosystem](https://vercel.com/docs/ai-gateway/ecosystem?from=related&source_path=%2Fkb%2Fguide%2Fchained-openai-llm-calls-vercel-inngest&source_site=vercel-kb&relationship=related) — Explore community framework integrations and ecosystem features for the AI Gateway.
- [Vercel & OpenAI Integration](https://vercel.com/docs/agent-resources/integrations-for-models/openai?from=related&source_path=%2Fkb%2Fguide%2Fchained-openai-llm-calls-vercel-inngest&source_site=vercel-kb&relationship=related) — Integrate your Vercel project with OpenAI's powerful suite of models.
- [LiteLLM](https://vercel.com/docs/ai-gateway/ecosystem/framework-integrations/litellm?from=related&source_path=%2Fkb%2Fguide%2Fchained-openai-llm-calls-vercel-inngest&source_site=vercel-kb&relationship=related) — Learn how to integrate Vercel AI Gateway with LiteLLM to access multiple AI models through a unified interface
- [LlamaIndex](https://vercel.com/docs/ai-gateway/ecosystem/framework-integrations/llamaindex?from=related&source_path=%2Fkb%2Fguide%2Fchained-openai-llm-calls-vercel-inngest&source_site=vercel-kb&relationship=related) — Learn how to integrate Vercel AI Gateway with LlamaIndex to access multiple AI models through a unified interface
- [Vercel Deployment Guide](https://ai-sdk.dev/docs/advanced/vercel-deployment-guide?from=related&source_path=%2Fkb%2Fguide%2Fchained-openai-llm-calls-vercel-inngest&source_site=vercel-kb&relationship=related)
- [What is a Large Language Model \\(LLM\\)?](https://vercel.com/kb/guide/what-is-a-large-language-model?from=related&source_path=%2Fkb%2Fguide%2Fchained-openai-llm-calls-vercel-inngest&source_site=vercel-kb&relationship=related) — Learn what Large Language Models \\(LLMs\\) are, how they work, and how you can use them to generate UI, debug code, and i
- [Building an AI chatbot with Next.js, Langchain, and OpenAI](https://vercel.com/kb/guide/nextjs-langchain-vercel-ai?from=related&source_path=%2Fkb%2Fguide%2Fchained-openai-llm-calls-vercel-inngest&source_site=vercel-kb&relationship=related) — Dive into the world of LangChain.js and Next.js with our detailed guide. Learn how to set up a chatbot, structure output
- [Streaming responses from LLMs](https://vercel.com/kb/guide/streaming-from-llm?from=related&source_path=%2Fkb%2Fguide%2Fchained-openai-llm-calls-vercel-inngest&source_site=vercel-kb&relationship=related) — Learn how to use the AI SDK to stream LLM responses.
- [Building AI apps on Vercel: an overview](https://vercel.com/kb/guide/how-to-build-ai-app?from=related&source_path=%2Fkb%2Fguide%2Fchained-openai-llm-calls-vercel-inngest&source_site=vercel-kb&relationship=related) — Learn the key AI concepts and tools for building and scaling AI apps.
- [How to Use ML Models from Hugging Face in Vercel Functions](https://vercel.com/kb/guide/ml-models-hugging-face?from=related&source_path=%2Fkb%2Fguide%2Fchained-openai-llm-calls-vercel-inngest&source_site=vercel-kb&relationship=related) — This guide provides step-by-step instructions on how to integrate ML models from Hugging Face into Vercel Functions

Full cross-link map for this page: [/kb/guide/chained-openai-llm-calls-vercel-inngest.graph.md](/kb/guide/chained-openai-llm-calls-vercel-inngest.graph.md?from=related&source_path=%2Fkb%2Fguide%2Fchained-openai-llm-calls-vercel-inngest&source_site=vercel-kb&relationship=graph)
<!-- /docsgraph:related -->


## Introduction to LLMs

[Large-language modals (LLMs)](/guides/what-is-a-large-language-model) like [OpenAI GPT-4](/docs/integrations/openai) are revolutionizing many sectors due to their ability to comprehend and generate human-like text. They are pre-trained on vast amounts of data, allowing them to generate relevant responses to any given prompt.

> Fluid compute is a hybrid approach that bridges the gap between serverless and traditional servers. To learn more, read [Fluid Compute](https://vercel.com/docs/functions/fluid-compute) and to get started with using it, read [How to enable fluid compute](https://vercel.com/docs/functions/fluid-compute#how-to-enable-fluid-compute).

## Why Chain LLMs?

However, for more complex applications, single responses from an LLM might not suffice. Chaining, or executing multiple LLM calls in a series or parallel, can offer refined results.

Here are some of the benefits of chaining LLMs:

- Maintains contextual continuity in conversations.
  
- Allows for elaboration and expansion on a topic.
  
- Facilitates multi-turn interactions for a dynamic conversation.
  
- Aids in problem solving and planning by breaking down tasks.
  
- Enables error correction and feedback to improve model responses.
  

## Using Inngest SDK

[Inngest](https://www.inngest.com/) offers a solution to chain LLMs efficiently without infrastructure overhead. It provides:

- [Automatic retries](https://www.inngest.com/docs/functions/retries) and state preservation
  
- [Optional parallelization](https://www.inngest.com/docs/guides/step-parallelism) for performance
  
- Built-in [observability](https://www.inngest.com/docs/reference/functions/step-send-event) and transparency
  
- [Function cancellation](https://www.inngest.com/docs/functions/cancellation) capability
  

Here's an example:

```javascript
import { Inngest } from "inngest";

const inngest = new Inngest({ name: "Your Application Name" });

export const chain = inngest.createFunction(
  { name: "Function Name" },
  { event: "api/function.endpoint" },
  async ({ event, step }) => {
    const llm = new OpenAI();
    
    const task1 = await step.run("Task 1 Name", async () => {
      const prompt = "...";
      return await llm.createCompletion({
        model: "...",
        prompt: `${prompt}: ${event.data.input}`,
      });
    });

    const task2 = await step.run("Task 2 Name", async () => {
      const prompt = "...";
      return await llm.createCompletion({
        model: "...",
        prompt: `${prompt}: ${task1}`,
      });
    });

    await step.run("Save to DB", async () => {
      await db.collection.create({ task1, task2, requestID: event.data.requestID });
    });

    return { task1, task2 };
  },
)
```

In this example, we define a chained function that is triggered by a specific event.

It consists of two tasks – each generating a completion using [OpenAI's language model](/docs/integrations/openai) based on a given prompt and input.

The results of these tasks are then saved to a [database](https://vercel.com/storage/postgres).

## Deploying to Vercel

Functions created with Inngest can be served via HTTP and hosted on any platform, such as Vercel, a popular deployment platform for front-end and serverless functions.

For example, here's the code above as used in an [API endpoint on Vercel](https://vercel.com/guides/using-express-with-vercel):

```javascript
import { serve } from "inngest/next";

const inngest = new Inngest({ name: "Your Application Name" });

export const chain = inngest.createFunction(
   ...
) // chain code from above

export const handler = serve(inngest, [chain]);
```

You can then trigger this endpoint by sending a HTTP POST request:

```javascript
await inngest.send({
  name: "api/function.endpoint",
  data: {
    requestID: "...",
    input: "...",
  }
});
```

## Further Reading

For more information on chained LLMs, you can refer to the following resources:

- [Running chained LLMs with TypeScript in production](https://www.inngest.com/blog/running-chained-llms-typescript-in-production)
  
- [Inngest GitHub repository](https://github.com/inngest/inngest-js)