Quick overview
This workflow exposes an OpenAI-compatible /v1/chat/completions endpoint in n8n that forwards requests (including optional file attachments) to a configurable LLM HTTP provider, supporting both synchronous replies and asynchronous processing via a callback URL.
How it works
- Receives a POST request on /v1/chat/completions via a webhook, accepting JSON or multipart form-data with optional binary file uploads.
- Converts any uploaded files into OpenAI-style message content (images as image_url data URLs and other files as text entries) and merges them into the last user message.
- Prepares a job ID, extracts optional callback and provider override settings (URL and headers), and keeps the original request body for later use.
- If a callback URL is provided, immediately returns HTTP 202 with the job ID, then sends the request (without callback/provider fields) to the configured LLM provider endpoint.
- Formats the provider response (or error) into a completion payload with a status code and posts the result to the callback URL with job metadata.
- If no callback URL is provided, sends the request to the LLM provider synchronously and returns the provider response (or error) to the original caller with the same HTTP status code.
Setup
- Deploy this workflow and copy the production webhook URL for /v1/chat/completions to use as your OpenAI-compatible endpoint in your client or application.
- Configure the upstream LLM provider URL and any required authorization headers (either by sending them in the request body under provider.url/provider.headers or by using the default Google Generative Language OpenAI-compatible endpoint and supplying its auth header).
- If you want asynchronous mode, provide a reachable callback.url (and optional callback.method and callback.headers) that can accept the completion payload posted by this workflow.
- If you plan to send attachments, ensure your client can send multipart form-data with a JSON body field plus additional file fields so the workflow can convert them into message content.