Back to Templates

Route AI prompts between Anthropic, Google Gemini, Mistral and OpenAI

Created by

Created by: Triple 8 Labs || triple8labs
Triple 8 Labs

Last update

Last update 10 hours ago

Categories

Share


Quick Overview

This sub-workflow is called via Execute Workflow and routes a prompt to Anthropic, Google Gemini, Mistral, or OpenAI, then normalizes the model output into a single response field while estimating token usage and cost.

How it works

  1. Receives input from another workflow via the Execute Workflow trigger.
  2. Applies default settings, normalizes fields (provider, model, prompts, temperature, token limit, response format), and builds the provider-specific request payload.
  3. Estimates input tokens and stops the run if the prompt exceeds a safety threshold of the selected model’s context limit.
  4. Routes the request to the selected provider and calls the corresponding API (Anthropic Messages, Google Gemini generateContent, Mistral chat completions, or OpenAI chat completions).
  5. Extracts and normalizes the returned text (or an error message) into llm_response, and captures actual token usage when the provider returns it.
  6. Estimates output tokens and cost from a built-in pricing table, then returns the original input merged with response, model/provider used, token counts, and cost fields.

Setup

  1. Create credentials for each provider you plan to use: Anthropic API, Google AI (PaLM) API for Gemini, Mistral Cloud API, and/or OpenAI API.
  2. Set your preferred defaults in the CONFIG step (default provider, default model per provider, temperature, max tokens, and response format).
  3. Call this workflow from other workflows using Execute Workflow and pass at minimum a userPrompt field (optionally systemPrompt, llm_provider, model overrides, temperature, max_tokens, and response_format).
  4. Activate the workflow so it can be executed as a sub-workflow.