LiteLLM icon

LiteLLM

Interact with LiteLLM Gateway API

Actions8

Chat → Chat Completion

AI-generated

Summary

Sends a chat completion request to a LiteLLM gateway's /chat/completions endpoint with a model name and a list of role-tagged messages, and returns the gateway's full JSON response as one item per input item.

Inputs

  • model (required) — Model name as known to the LiteLLM gateway (e.g. gpt-4o, claude-3-sonnet). Errors if empty or whitespace.
  • messages (required) — One or more messages, each with a Role (system, user, assistant, tool, function, developer) and Content text. Errors if none are added. Only role and content are sent; tool_call_id or name fields are not supported.
  • additionalFields.temperature — Sampling temperature, 0–2.
  • additionalFields.top_p — Nucleus sampling, 0–1.
  • additionalFields.max_tokens — Maximum tokens to generate.
  • additionalFields.frequency_penalty — Frequency penalty, -2 to 2.
  • additionalFields.presence_penalty — Presence penalty, -2 to 2.
  • additionalFields.stop — Comma-separated stop sequences; split on commas and trimmed into an array.
  • additionalFields.seed — Seed for reproducible sampling.
  • additionalFields.response_format — Text or JSON Object. Only json_object is sent, as {type: "json_object"}; text omits the field.
  • additionalFields.tools — JSON array of tool definitions, parsed before sending. Invalid JSON throws an error.
  • additionalFields.tool_choice — "none", "auto", "required", or a JSON object string. Parsed as JSON if possible, otherwise sent as a plain string.

Output shape

One output item per input item, whose json is the raw gateway response (OpenAI-style: choices, usage, model, id, and any tool_calls).

The request and full response are written to the n8n logger at info level, so prompts and completions appear in logs. Authentication uses the liteLLMApi credential (base URL and API key, sent in the x-litellm-api-key header). Streaming is not supported. With Continue On Fail enabled, failures yield an item with error and statusCode. Otherwise errors are raised as NodeApiError with friendly messages for 401, 404, 429 and 500, or for connection failures.

Examples

Example 1: Summarize incoming text with a system prompt

Model: gpt-4o. Messages: system "Summarize in 3 bullets", user set to an expression like {{$json.text}}. Temperature 0.2.

Example 2: Get structured JSON output

Add a system message asking for JSON, set Response Format to JSON Object, then parse choices[0].message.content downstream.

Example 3: Let the model call a function

Set Tools to a JSON array of function definitions and Tool Choice to auto; read choices[0].message.tool_calls from the output.

Links

Discussion