Universal OpenAI API Endpoint Creator for AI Agents - n8n Workflow

Use this powerful n8n workflow to create universal OpenAI-compatible API endpoints for all your custom n8n AI agents and LLM automation logic, supporting both streaming and standard responses.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Automation Specialists who want to expose their n8n workflow logic as standardized AI models.
Developers building frontends or third-party applications that require an OpenAI-compatible API structure.
Users seeking to deploy n8n templates as scalable, external LLM services.
Anyone needing robust core logic flow control for AI services within n8n.

Overview

This sophisticated n8n workflow provides a standardized façade for all your underlying n8n AI agents. Instead of configuring unique API calls for every different n8n workflow, this solution creates two universal endpoints mimicking the behavior of the native OpenAI API: one for listing available models (/models) and one for executing chat completions (/chat/completions).

When you use this n8n template, it automatically discovers all your internal n8n workflows tagged 'aimodel' and lists them as available AI models. When a chat request comes in, the n8n workflow processes the request, intelligently transforms the input schema (handling complex inputs like image URLs), routes the request to the correct internal n8n agent via an HTTP Request n8n node, and meticulously formats the output, supporting both standard JSON responses and real-time Server-Sent Event (SSE) streaming responses, exactly like a high-end OpenAI API implementation.

How it Works

This n8n workflow operates based on two distinct webhook triggers, providing comprehensive OpenAI API mimicry:

1. Model Listing Endpoint (GET /youragents/models)


  1. The GET models n8n trigger (a Webhook n8n node) receives an incoming GET request.

  2. The Get many workflows n8n node queries the internal n8n instance for all active n8n workflows that possess the tag aimodel.

  3. The Edit Fields n8n node extracts crucial metadata (name, ID, and the internal webhook path of the targeted n8n workflow).

  4. The data is aggregated and sent to the Models Response n8n node, which structures the output into the required OpenAI /models JSON format, listing all your custom n8n templates.

2. Chat Completion Endpoint (POST /youragents/chat/completions)


  1. The POST ChatCompletions n8n trigger (Webhook n8n node with header authentication) receives a chat request payload.

  2. The Remap to Response API Schema Code n8n node translates the incoming OpenAI message structure (which might contain complex content types like image_url) into a simplified JSON structure suitable for execution by the target n8n agent workflow.

  3. The Is Stream? If n8n node checks the incoming payload for the stream: true parameter.

  4. If Streaming (True Branch): The Call workflow webhook HTTP Request n8n node calls the webhook of the specific internal n8n workflow corresponding to the requested model. The Format Stream Response Code n8n node wraps the output into standard SSE chunks (data: {...}\n\ndata: [DONE]). The Text Response n8n node sends this data back with the correct headers for real-time streaming.

  5. If Standard Response (False Branch): The Call workflow webhook1 HTTP Request n8n node executes the internal n8n agent. The Format Completion Response Code n8n node structures the output into the standard OpenAI chat completion JSON schema. The JSON Response n8n node returns the final JSON output.

Installation Guide

To deploy this powerful n8n workflow, follow these steps:


  1. Import: Copy the entire n8n workflow JSON and paste it into your n8n canvas using the 'New' -> 'Import from JSON' option.

  2. Activate Authentication: The POST ChatCompletions n8n trigger node requires 'Header Auth'. You must configure a webhook credential to secure this API endpoint.

  3. Setup Target Workflows: Ensure that any n8n workflow you wish to expose as a model is tagged with aimodel and contains a Webhook n8n node (or Chat Trigger) to receive requests.

  4. n8n API Credential: The HTTP Request n8n nodes (Call workflow webhook and Call workflow webhook1) rely on an internal n8nApi credential type. This is crucial for securely calling webhooks within your own n8n instance. Configure this credential to ensure the routing works correctly.

  5. Base URL Customization: The HTTP Request n8n nodes use a placeholder URL (e.g., https://n8n.lucidusfortis.com). You must update this URL to match the public URL of your own n8n instance.

Node Details

GET models / POST ChatCompletions (Webhook n8n trigger nodes): These nodes serve as the external entry points. They listen on specific paths (youragents/models and youragents/chat/completions) to receive and initiate the n8n workflow execution.
Get many workflows (n8n node): Essential for the /models endpoint, this n8n node queries the list of all internal n8n workflows, filtering specifically by the aimodel tag, enabling dynamic model discovery.
Edit Fields (Set n8n node): Used to map the raw internal n8n workflow metadata into the required id and path variables needed for the OpenAI /models response schema.
Remap to Response API Schema (Code n8n node): Handles complex data transformation, converting the standard OpenAI input structure (including image links and text blocks) into a consumable format for internal n8n agents. This is vital for maintaining compatibility across different n8n templates.
Is Stream? (If n8n node): Provides core logic flow control, routing the execution path based on whether the inbound API call requested a streaming response (stream: true) or a standard synchronous response.
Call workflow webhook / Call workflow webhook1 (HTTP Request n8n node): These nodes execute the core LLM logic by making an authenticated POST call to the internal webhook of the specified target n8n workflow. They are crucial for routing the request to the correct n8n agent.

Related n8n Workflows

Free

Nodes: 13 Nodes
Updated: December 26 2025
View all
Created by

Award winning IT pro. Serial entrepreneur. Mentor. Investor. Ex-MD/VP Cavista Holdings. Builds tech solutions for business problems. Founder, Lucidus Fortis.

Featured*