AI Completion

Run LLM completions from multiple providers within a flow. Supports custom OpenAI-compatible endpoints, tool calling via MCP servers, streaming, and RAG via static context.

Configuration

- ai_completion:
    name: analyze
    provider: google
    model: gemini-2.5-flash-lite
    credentials_path: "{{env.FLOWGEN_CREDENTIALS}}/google.json"
    prompt: "Analyze this data: {{event.data}}"

Fields

FieldTypeDefaultDescription
namestringrequiredTask name.
providerstringrequiredLLM provider — see Providers below.
modelstringrequiredModel identifier (e.g. gpt-4, claude-3-5-sonnet-20241022, gemini-2.5-flash-lite).
promptstring/resourcerequiredUser prompt template. Supports handlebars templating and resource files.
credentials_pathstringPath to provider credentials JSON. Required for API-key providers, optional for vertexai, ollama and custom.
vertexaiobjectOptions of provider: vertexai: project_id (default GOOGLE_CLOUD_PROJECT, else the service account key’s project_id) and location (default GOOGLE_CLOUD_LOCATION, else global). Set with another provider, the task fails to load.
endpointstringBase URL of a custom OpenAI-compatible endpoint. Required when provider: custom or provider: ollama. Example: https://llm-gateway.internal.example.com/v1.
headersmap of string to stringHTTP headers sent with every request (provider: custom/ollama only), such as a key the endpoint requires.
system_promptstring/resourceSystem prompt.
max_tokensintMaximum tokens in response.
temperaturefloatSampling temperature (0.0–1.0).
streamboolfalseStream response as separate events instead of one final event.
static_contextlistRAG documents (inline strings or resource: references) always available to the agent.
max_turnsint10Most model calls one event may make, tool calls included. At least 1, and at least 2 with mcp_servers: one call to use a tool and one to answer.
mcp_serverslistMCP server URLs for tool discovery. The agent connects to each, discovers tools, and makes them callable during completion. The servers’ instructions follow system_prompt.
tool_passthroughboolfalseSkip rig’s agent loop and forward caller-supplied tools verbatim to the upstream provider. See Tool-use passthrough.
output_schemaobjectJSON Schema the answer must match. The answer stays JSON text in text; parse it with parse_json in a script.
imageslist of stringImages sent with the prompt, for models that read images: http(s) URLs, downloaded and sent as base64, or base64 data: URLs. Each must be a PNG, JPEG, GIF, WebP, HEIC, HEIF or SVG image of at most image_max_bytes. A URL must reach a public address: loopback, private, link-local and other non-public addresses are refused, also after a redirect, and proxy settings are not used. A refused, empty or malformed URL fails the event without a retry. Supports handlebars templating.
image_timeoutduration30sHow long fetching one image may take.
image_max_bytesinteger20971520Largest image sent to the model, in bytes.
depends_onlistUpstream task names.
retryobjectRetry configuration. A provider error is retried on 408, 425, 429, a 5xx or a failed connection; other 4xx fail at once.

Providers

ProviderAuthRequired credentials fields
openaiAPI keyapi_key
anthropicAPI keyapi_key
googleAPI key (Gemini API)api_key
cohereAPI keyapi_key
mistralAPI keyapi_key
groqAPI keyapi_key
togetherAPI keyapi_key
xaiAPI keyapi_key
openrouterAPI keyapi_key
perplexityAPI keyapi_key
huggingfaceAPI keyapi_key
vertexaiService account key, or Google ADC without credentials_paththe service account key file
ollamaOptional API keyoptional api_key
customOptional API keyoptional api_key

For providers not listed above (cloud-native services with non-api_key auth, on-prem model servers, multi-tenant routing), set provider: custom and point endpoint at any service speaking the OpenAI chat-completions wire format. The flowgen AI gateway (llm_proxy task) can itself act as that endpoint, letting you route, log, and rate-limit across upstream models from one place.

Credentials file format

For API-key providers, credentials file is a simple JSON:

{ "api_key": "sk-..." }

For vertexai, credentials_path points at a service account key file. Without it, flowgen signs in with Google Application Default Credentials, such as workload identity. The project and location are vertexai options:

- ai_completion:
    name: analyze
    provider: vertexai
    model: gemini-2.5-flash
    vertexai:
      project_id: my-project
      location: europe-west4
    prompt: "Analyze this data: {{event.data}}"

Example: custom OpenAI-compatible endpoint

Point at any service speaking the OpenAI chat-completions wire format — an internal model server, a self-hosted gateway, or the flowgen AI gateway itself routing to one or more upstream models.

- ai_completion:
    name: internal_llm
    provider: custom
    model: my-internal-model
    endpoint: "https://llm-gateway.internal.example.com/v1"
    credentials_path: "{{env.FLOWGEN_CREDENTIALS}}/internal-llm.json"
    prompt: "{{event.data.question}}"

For endpoints without auth, omit credentials_path:

- ai_completion:
    name: unauth_endpoint
    provider: custom
    model: my-model
    endpoint: "http://llm.cluster.local/v1"
    prompt: "{{event.data}}"

Example: RAG with static context

static_context documents are injected into every completion. Mix inline strings and resource files.

- ai_completion:
    name: support_bot
    provider: openai
    model: gpt-4-turbo
    credentials_path: "{{env.FLOWGEN_CREDENTIALS}}/openai.json"
    system_prompt: "Answer using the provided context."
    prompt: "{{event.data.question}}"
    static_context:
      - resource: "docs/product_manual.md"
      - resource: "docs/pricing.md"
      - "Support contact: [email protected]"
    max_turns: 3

Example: structured answer with an image

The model answers JSON matching output_schema.

- ai_completion:
    name: describe_image
    provider: openai
    model: gpt-4.1
    credentials_path: "{{env.FLOWGEN_CREDENTIALS}}/openai.json"
    prompt: "Describe the image."
    images: ["{{event.data.image_url}}"]
    output_schema:
      type: object
      properties:
        summary: { type: string }
        tags: { type: array, items: { type: string } }
      required: [summary, tags]

- script:
    name: read_answer
    code: parse_json(event.data.text)

Example: MCP tool calling

The agent connects to MCP servers, discovers tools, and can call them during completion. Use flowgen’s own MCP server (mcp_tool task) or any external MCP-compatible server.

- ai_completion:
    name: agent
    provider: anthropic
    model: claude-3-5-sonnet-20241022
    credentials_path: "{{env.FLOWGEN_CREDENTIALS}}/anthropic.json"
    prompt: "{{event.data.task}}"
    max_turns: 5
    mcp_servers:
      - url: "http://127.0.0.1:3001/mcp/v1"
      - url: "http://external-tools:8080/mcp"

Optional per-server auth uses the same credentials JSON format as http_request (bearer_auth, basic_auth, or oauth2_client_credentials):

    mcp_servers:
      - url: "https://tools.example.com/mcp"
        credentials_path: "{{env.FLOWGEN_CREDENTIALS}}/mcp-tools.json"

For MCP servers that require OAuth 2.0, use the oauth2_client_credentials format in the credentials file — flowgen fetches and refreshes the access token automatically:

{
  "oauth2_client_credentials": {
    "token_url": "https://auth.example.com/oauth2/token",
    "client_id": "my-client-id",
    "client_secret": "my-client-secret",
    "scope": "api"
  }
}

Each entry also accepts headers, sent with every request to that MCP server, such as a key the server requires. To give an agent only the tools of one folder of flows, connect it to that folder’s toolset URL:

    mcp_servers:
      - url: "http://127.0.0.1:3001/mcp/v1/sales"

allowed_tools names the tools of that server the agent uses; the others stay out of the model’s tool list. Without it the agent gets every tool the server lists:

    mcp_servers:
      - url: "http://127.0.0.1:3001/mcp/v1"
        allowed_tools: [web_search, read_page]

When two servers give the agent a tool of the same name, the agent keeps the first server’s and logs a warning. prefix tells the servers’ tools apart: the agent sees each of that server’s tools as the prefix followed by its name, and calls reach the server under the original name. A prefix is letters, digits, _ or -; allowed_tools still names the original tools.

    mcp_servers:
      - url: "http://127.0.0.1:3001/mcp/v1/notes"
      - url: "https://mcp.example.com/mcp"
        prefix: notes_

A server with a prefix keeps the tools it listed when the agent connected; tools it adds later reach the agent when the agent reconnects.

Calling tools as the signed-in user

With on_behalf_of_user: true, the agent calls the server as the user who sent the request, with their token as the bearer:

    mcp_servers:
      - url: "http://127.0.0.1:3001/mcp/v1"
        on_behalf_of_user: true
  • The token is the bearer that an llm_proxy, http_endpoint, or mcp_tool verified with the worker’s auth provider. This includes Agents chat requests when web.agents.on_behalf_of_user is set. A buffer keeps it when every event in a batch comes from the same user.
  • Set it only for servers that accept tokens from the same auth, such as this instance’s MCP server; the agent warns at startup about any other.
  • Setting it together with credentials_path fails the task at startup.
  • Without a signed-in user, the call carries no token. A 401 or 403 from the server fails the request without a retry.
  • Each user gets their own connections and agent client, closed after 30 minutes without a request. A new token opens new connections. A request already running keeps its own until it finishes.

Tool-use passthrough

When tool_passthrough: true, the task bypasses rig’s agent loop and forwards caller-supplied tools and tool_choice (from the request body) directly to the upstream provider. Tool invocations returned by the model surface as tool_calls on the response instead of being executed in-process. The client, typically one of the MCP clients such as coding agents and chat apps, runs the tools locally and posts the results back as role: "tool" follow-up messages.

Use this mode when flowgen is the AI gateway for a tool-executing client. Leave it false for agent-mode flows that execute tools themselves via mcp_servers or inline definitions.

- llm_proxy:
    name: proxy

- ai_completion:
    name: forward
    provider: custom
    endpoint: "{{event.data.endpoint}}"
    model: "{{event.data.routed_model}}"
    credentials_path: "{{event.data.credentials_path}}"
    prompt: "{{event.data.prompt}}"
    system_prompt: "{{event.data.system_prompt}}"
    tool_passthrough: true
    stream: true

Passthrough is a no-op when the request omits tools: the flow follows the normal completion path so a single ai_completion task can serve both tool-using and plain chat clients without a second flow.

Works across every provider flowgen supports (OpenAI, Anthropic, Cohere, Gemini, Mistral, Groq, Together, xAI, OpenRouter, Perplexity, HuggingFace, VertexAI, and any OpenAI-compatible endpoint via provider: custom). Provider-native quirks in the tool schema — Anthropic’s tool_use block, Google’s parallel-call ordering — are handled by the underlying rig client without any per-provider config here.

Output

Format: JSON

FieldTypeDescription
textstringGenerated completion text.
modelstringModel used.
providerstringProvider name.
usageobjectToken counts (prompt_tokens, completion_tokens, total_tokens).

In stream: true mode, each chunk is emitted as a separate event with partial text content.

Get the edge.

News, releases, and insights — no noise.

ul. Złota 75A lok. 7, 00-819 Warszawa HQ
NIP 5090052574 · REGON 381354056
Copyright © 2026 CONNVE. All rights reserved.