{
  "slug": "slim-anthropic-messages-response-chat",
  "title": "Anthropic messages api response slim for chat ui",
  "metaTitle": "Anthropic messages api response - RealComposer",
  "metaDescription": "Anthropic messages api response slim for chat ui. Map content blocks and stop reason; drop billing debug. Map only UI fields from Anthropic before.",
  "headline": "Chat bubbles without raw usage debug blobs",
  "category": "slimmer",
  "categoryLabel": "Payload Slimmer",
  "urgency": 8,
  "clientPlatform": "Next.js / React",
  "upstreamServices": [
    "Anthropic"
  ],
  "searchIntentQuery": "anthropic messages api response slim for chat ui",
  "directAnswerSummary": "Map content blocks and stop reason; drop billing debug fields. For \"anthropic messages api response slim for chat ui\", store ANTHROPIC_API_KEY in Secret Vault, call https://api.anthropic.com/v1/messages from a Worker, and let Next.js / React hit only https://realcomposer.com/v1/workspace/slim-anthropic-messages-response-chat 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": "Unmapped Anthropic fields waste bandwidth",
    "explanation": "Anthropic returns nested CRM, audit, and configuration objects. Next.js / React parses them on the main thread even when the UI binds three fields.",
    "risks": [
      "Large arrays kept in memory after navigation",
      "Analytics showing poor LCP on API-heavy screens",
      "Developers shipping defensive null checks for unused paths"
    ]
  },
  "solutionSteps": [
    {
      "stepNumber": 1,
      "title": "Bind vault keys to the Worker",
      "description": "Create ANTHROPIC_API_KEY vault entries, then bind them to this pipeline step headers with {{secrets.NAME}} placeholders."
    },
    {
      "stepNumber": 2,
      "title": "Target the real upstream URL",
      "description": "Use POST against https://api.anthropic.com/v1/messages. Allowed origins on the client token should match post pipelines set cache ttl to 0 because realcomposer only stores get responses at the edge."
    },
    {
      "stepNumber": 3,
      "title": "Call from Next.js / React",
      "description": "Call https://realcomposer.com/v1/workspace/slim-anthropic-messages-response-chat with a restricted rc_live_ client token. Next.js / React never sends upstream secrets.",
      "codeSnippet": "// app/api route or client component\nconst res = await fetch('https://realcomposer.com/v1/workspace/slim-anthropic-messages-response-chat', {\n  cache: 'no-store',\n  headers: { Authorization: 'Bearer rc_live_your_token' }\n});"
    }
  ],
  "pipelineConfig": {
    "name": "Anthropic messages api response slim for chat ui",
    "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": 10000
      }
    ],
    "outputMapping": {
      "version": 1,
      "fields": [
        {
          "targetPath": "role",
          "sourcePath": "content.0.text",
          "type": "string",
          "sourceStep": "anthropic"
        },
        {
          "targetPath": "model",
          "sourcePath": "model",
          "type": "string",
          "sourceStep": "anthropic"
        },
        {
          "targetPath": "stopReason",
          "sourcePath": "stop_reason",
          "type": "string",
          "sourceStep": "anthropic"
        }
      ]
    }
  },
  "sampleBloatedInput": {
    "requestId": "req_slim-ant",
    "upstreamLatencyMs": 142,
    "audit": {
      "region": "edge",
      "trace": "slim-anthropic-messages-response-chat"
    },
    "payload": {
      "id": "sample_id",
      "status": "active",
      "nested": {
        "tags": [
          "demo"
        ],
        "internal": true
      },
      "unused_blob": {
        "foo": "bar",
        "bar": "baz"
      }
    }
  },
  "sampleSlimmedOutput": {
    "role": "sample",
    "model": "sample",
    "stopReason": "sample"
  },
  "curlSnippet": "curl -X POST \"https://realcomposer.com/v1/workspace/slim-anthropic-messages-response-chat\" \\\n  -H \"Authorization: Bearer rc_live_client_token\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"model\":\"example\"}'",
  "faqs": [
    {
      "question": "Is it safe to log Anthropic responses in Next.js / React?",
      "answer": "Point Next.js / React at /recipes/slim-anthropic-messages-response-chat edge URL. RealComposer answers OPTIONS with Access-Control headers for allowed origins."
    },
    {
      "question": "Will Anthropic or Linear prompt bodies be rewritten?",
      "answer": "slim-anthropic-messages-response-chat keeps cache TTL at 0 because it uses POST upstream calls or per-user responses. Add ids to query strings before enabling GET cache."
    },
    {
      "question": "How do I rotate upstream credentials?",
      "answer": "Rotate vault secrets for slim-anthropic-messages-response-chat anytime; clients keep the same rc_live_ token."
    }
  ],
  "relatedRecipeSlugs": [
    "slim-notion-block-children-payload",
    "reduce-json-payload-size-frontend"
  ],
  "updatedAt": "2026-11-20",
  "links": {
    "page": "https://realcomposer.com/recipes/slim-anthropic-messages-response-chat",
    "markdown": "https://realcomposer.com/recipes/slim-anthropic-messages-response-chat.md",
    "json": "https://realcomposer.com/recipes/slim-anthropic-messages-response-chat.json",
    "install": "https://realcomposer.com/dashboard/pipelines/new?recipe=slim-anthropic-messages-response-chat&via=agent"
  }
}