{
  "slug": "combine-anthropic-with-openai-fallback",
  "title": "Combine anthropic claude with openai fallback router",
  "metaTitle": "Combine anthropic claude with - RealComposer",
  "metaDescription": "Combine anthropic claude with openai fallback router. Merge Anthropic and OpenAI in one Frontend / Web call with parallel Worker steps.",
  "headline": "Multi-model chat with one client endpoint",
  "category": "aggregation",
  "categoryLabel": "Multi-API Aggregation",
  "urgency": 9,
  "clientPlatform": "Frontend / Web",
  "upstreamServices": [
    "Anthropic",
    "OpenAI"
  ],
  "searchIntentQuery": "combine anthropic claude with openai fallback router",
  "directAnswerSummary": "Primary Anthropic Messages step plus OpenAI fallback step in one pipeline. For \"combine anthropic claude with openai fallback router\", store ANTHROPIC_API_KEY, OPENAI_API_KEY in Secret Vault, call https://api.anthropic.com/v1/messages from a Worker, and let Frontend / Web hit only https://realcomposer.com/v1/workspace/combine-anthropic-with-openai-fallback with an rc_live_ client token. POST upstream calls are not stored in caches.default; clients must send JSON bodies and headers forward unchanged.",
  "problem": {
    "title": "Serial Anthropic and OpenAI calls slow Frontend / Web pages",
    "explanation": "Each extra Anthropic and OpenAI hop adds hundreds of milliseconds and another OAuth refresh path your UI must manage.",
    "risks": [
      "One slow upstream blocking an entire page",
      "Partial failures leaving UI in inconsistent states",
      "Duplicate auth refresh logic per service"
    ]
  },
  "solutionSteps": [
    {
      "stepNumber": 1,
      "title": "Add vault secrets for this pipeline",
      "description": "Store ANTHROPIC_API_KEY, OPENAI_API_KEY in the vault. Frontend / Web never embeds the raw secret, only a revocable rc_live_ client token."
    },
    {
      "stepNumber": 2,
      "title": "Target the real upstream URL",
      "description": "Configure headersTemplate to inject vault secrets, target https://api.anthropic.com/v1/messages, and Add output mapping fields that mirror the JSON contract your screen already expects."
    },
    {
      "stepNumber": 3,
      "title": "Call from Frontend / Web",
      "description": "Allowed origins on the token should list every Frontend / Web host that calls this URL.",
      "codeSnippet": "const res = await fetch('https://realcomposer.com/v1/workspace/combine-anthropic-with-openai-fallback', {\n  headers: { Authorization: 'Bearer rc_live_your_token' }\n});"
    }
  ],
  "pipelineConfig": {
    "name": "Combine anthropic claude with openai fallback router",
    "method": "POST",
    "cacheTtlSeconds": 0,
    "authMode": "client_token",
    "steps": [
      {
        "stepKey": "anthropic",
        "upstreamUrlTemplate": "https://api.anthropic.com/v1/messages",
        "httpMethod": "POST",
        "headersTemplate": {
          "x-api-key": "{{secrets.ANTHROPIC_API_KEY}}",
          "anthropic-version": "2023-06-01",
          "Content-Type": "application/json"
        },
        "timeoutMs": 15000
      },
      {
        "stepKey": "openai",
        "upstreamUrlTemplate": "https://api.openai.com/v1/chat/completions",
        "httpMethod": "POST",
        "headersTemplate": {
          "Authorization": "Bearer {{secrets.OPENAI_API_KEY}}",
          "Content-Type": "application/json"
        },
        "timeoutMs": 15000
      }
    ],
    "outputMapping": {
      "version": 1,
      "fields": [
        {
          "targetPath": "anthropic.role",
          "sourcePath": "content.0.text",
          "type": "string",
          "sourceStep": "anthropic"
        },
        {
          "targetPath": "anthropic.model",
          "sourcePath": "model",
          "type": "string",
          "sourceStep": "anthropic"
        },
        {
          "targetPath": "openai.reply",
          "sourcePath": "choices.0.message.content",
          "type": "string",
          "sourceStep": "openai"
        },
        {
          "targetPath": "openai.tokens",
          "sourcePath": "usage.total_tokens",
          "type": "number",
          "sourceStep": "openai"
        }
      ]
    }
  },
  "sampleBloatedInput": {
    "requestId": "req_combine-",
    "upstreamLatencyMs": 142,
    "audit": {
      "region": "edge",
      "trace": "combine-anthropic-with-openai-fallback"
    },
    "payload": {
      "id": "sample_id",
      "status": "active",
      "nested": {
        "tags": [
          "demo"
        ],
        "internal": true
      },
      "unused_blob": {
        "foo": "bar",
        "bar": "baz"
      }
    }
  },
  "sampleSlimmedOutput": {
    "anthropic_role": "sample",
    "anthropic_model": "sample",
    "openai_reply": "sample",
    "openai_tokens": "sample"
  },
  "curlSnippet": "curl -X POST \"https://realcomposer.com/v1/workspace/combine-anthropic-with-openai-fallback\" \\\n  -H \"Authorization: Bearer rc_live_client_token\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"model\":\"example\"}'",
  "faqs": [
    {
      "question": "Can Frontend / Web call Anthropic without holding the production key?",
      "answer": "Use scoped tokens where the vendor allows them on combine-anthropic-with-openai-fallback. Admin keys stay {{secrets.*}} references only."
    },
    {
      "question": "How do I forward JSON bodies to POST upstreams?",
      "answer": "combine-anthropic-with-openai-fallback POST steps bypass caches.default even if cacheTtlSeconds is set in the dashboard."
    },
    {
      "question": "How do I rotate upstream credentials?",
      "answer": "Rotate vault secrets for combine-anthropic-with-openai-fallback anytime; clients keep the same rc_live_ token."
    }
  ],
  "relatedRecipeSlugs": [
    "anthropic-claude-api-frontend-proxy",
    "hide-openai-api-key-react"
  ],
  "updatedAt": "2026-11-20",
  "links": {
    "page": "https://realcomposer.com/recipes/combine-anthropic-with-openai-fallback",
    "markdown": "https://realcomposer.com/recipes/combine-anthropic-with-openai-fallback.md",
    "json": "https://realcomposer.com/recipes/combine-anthropic-with-openai-fallback.json",
    "install": "https://realcomposer.com/dashboard/pipelines/new?recipe=combine-anthropic-with-openai-fallback&via=agent"
  }
}