{
  "slug": "combine-openai-and-supabase-vector-search",
  "title": "Combine Openai Embeddings and Supabase Vector Search in One Call",
  "metaTitle": "Combine Openai Embeddings and - RealComposer",
  "metaDescription": "Combine openai embeddings and supabase vector search in one call. Merge OpenAI and Supabase in one Frontend / Web call with parallel Worker steps.",
  "headline": "Parallel OpenAI fetch merged before Frontend / Web hydrates",
  "category": "aggregation",
  "categoryLabel": "Multi-API Aggregation",
  "urgency": 9,
  "clientPlatform": "Frontend / Web",
  "upstreamServices": [
    "OpenAI",
    "Supabase"
  ],
  "searchIntentQuery": "combine openai embeddings and supabase vector search in one call",
  "directAnswerSummary": "Instead of Frontend / Web firing serial fetches to OpenAI and Supabase, one pipeline hits https://api.openai.com/v1/embeddings (and sibling steps) in parallel and returns mapped JSON.",
  "problem": {
    "title": "Waterfall latency from multiple OpenAI and Supabase requests",
    "explanation": "Frontend / Web widgets often await OpenAI and Supabase sequentially, multiplying TLS handshakes on cellular networks and amplifying failure rates.",
    "risks": [
      "Race conditions between parallel manual fetches",
      "Higher mobile data usage from redundant JSON",
      "Timeouts when any upstream exceeds cellular RTT"
    ]
  },
  "solutionSteps": [
    {
      "stepNumber": 1,
      "title": "Add vault secrets for this pipeline",
      "description": "Create OPENAI_API_KEY, SUPABASE_SERVICE_ROLE_KEY vault entries, then bind them to this pipeline step headers with {{secrets.NAME}} placeholders."
    },
    {
      "stepNumber": 2,
      "title": "Target the real upstream URL",
      "description": "Point step openai at https://api.openai.com/v1/embeddings with POST. Add output mapping fields that mirror the JSON contract your screen already expects. POST pipelines set cache TTL to 0 because RealComposer only stores GET responses at the edge."
    },
    {
      "stepNumber": 3,
      "title": "Call from Frontend / Web",
      "description": "Call https://realcomposer.com/v1/workspace/combine-openai-and-supabase-vector-search with a restricted rc_live_ client token. Frontend / Web never sends upstream secrets.",
      "codeSnippet": "const res = await fetch('https://realcomposer.com/v1/workspace/combine-openai-and-supabase-vector-search', {\n  headers: { Authorization: 'Bearer rc_live_your_token' }\n});"
    }
  ],
  "pipelineConfig": {
    "name": "Combine Openai Embeddings and Supabase Vector Search in One Call",
    "method": "POST",
    "cacheTtlSeconds": 0,
    "authMode": "client_token",
    "steps": [
      {
        "stepKey": "openai",
        "upstreamUrlTemplate": "https://api.openai.com/v1/embeddings",
        "httpMethod": "POST",
        "headersTemplate": {
          "Authorization": "Bearer {{secrets.OPENAI_API_KEY}}",
          "Content-Type": "application/json"
        },
        "timeoutMs": 15000
      },
      {
        "stepKey": "supabase",
        "upstreamUrlTemplate": "https://{{secrets.SUPABASE_PROJECT_REF}}.supabase.co/rest/v1/rpc/match_documents",
        "httpMethod": "POST",
        "headersTemplate": {
          "apikey": "{{secrets.SUPABASE_SERVICE_ROLE_KEY}}",
          "Authorization": "Bearer {{secrets.SUPABASE_SERVICE_ROLE_KEY}}",
          "Content-Type": "application/json"
        },
        "timeoutMs": 5000
      }
    ],
    "outputMapping": {
      "version": 1,
      "fields": [
        {
          "targetPath": "openai.reply",
          "sourcePath": "choices.0.message.content",
          "type": "string",
          "sourceStep": "openai"
        },
        {
          "targetPath": "openai.tokens",
          "sourcePath": "usage.total_tokens",
          "type": "number",
          "sourceStep": "openai"
        },
        {
          "targetPath": "supabase.rowId",
          "sourcePath": "0.id",
          "type": "string",
          "sourceStep": "supabase"
        },
        {
          "targetPath": "supabase.email",
          "sourcePath": "0.email",
          "type": "string",
          "sourceStep": "supabase"
        }
      ]
    }
  },
  "sampleBloatedInput": {
    "requestId": "req_combine-",
    "upstreamLatencyMs": 142,
    "audit": {
      "region": "edge",
      "trace": "combine-openai-and-supabase-vector-search"
    },
    "payload": {
      "id": "sample_id",
      "status": "active",
      "nested": {
        "tags": [
          "demo"
        ],
        "internal": true
      },
      "unused_blob": {
        "foo": "bar",
        "bar": "baz"
      }
    }
  },
  "sampleSlimmedOutput": {
    "openai_reply": "sample",
    "openai_tokens": "sample",
    "supabase_rowId": "sample",
    "supabase_email": "sample"
  },
  "curlSnippet": "curl -X POST \"https://realcomposer.com/v1/workspace/combine-openai-and-supabase-vector-search\" \\\n  -H \"Authorization: Bearer rc_live_client_token\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"model\":\"example\"}'",
  "faqs": [
    {
      "question": "Does Frontend / Web need CORS changes after adding RealComposer?",
      "answer": "Yes for combine-openai-and-supabase-vector-search. Ship only an rc_live_ client token in Frontend / Web; RealComposer injects OPENAI_API_KEY on https://api.openai.com/v1/embeddings."
    },
    {
      "question": "What cache key does RealComposer use?",
      "answer": "combine-openai-and-supabase-vector-search forwards client JSON to POST upstreams unchanged; secrets interpolate only in URLs and header templates."
    },
    {
      "question": "How do I rotate upstream credentials?",
      "answer": "Upstream steps in combine-openai-and-supabase-vector-search honor timeoutMs and optional fallback JSON without leaking secrets."
    }
  ],
  "relatedRecipeSlugs": [
    "shopify-admin-api-frontend-proxy",
    "json-optimizer-low-bandwidth",
    "plaid-api-proxy-flutter"
  ],
  "updatedAt": "2026-11-20",
  "links": {
    "page": "https://realcomposer.com/recipes/combine-openai-and-supabase-vector-search",
    "markdown": "https://realcomposer.com/recipes/combine-openai-and-supabase-vector-search.md",
    "json": "https://realcomposer.com/recipes/combine-openai-and-supabase-vector-search.json",
    "install": "https://realcomposer.com/dashboard/pipelines/new?recipe=combine-openai-and-supabase-vector-search&via=agent"
  }
}