← Blog

Claude API React Native App Integration Guide

2026-11-12 · 5 min read · SubToAPI Team

Integrating the Claude API into a React Native app means answering one question first: where does the Anthropic request actually happen? It can't happen directly inside your app bundle, because any API key shipped in a mobile build can be extracted and abused. The practical answer is that your React Native app talks to an HTTPS endpoint you control (or a managed one), and that endpoint holds the credentials and forwards requests to Claude.

This article covers the architecture, the React Native client code for both plain and streaming responses, how to handle tool use from a mobile UI, and the gotchas specific to iOS and Android networking that trip people up when they first wire this together.

Why you can't call Claude directly from the app

Claude's API expects an x-api-key header on every request. If you hardcode that key in JavaScript that ships inside a React Native bundle, it's recoverable with basic reverse engineering tools — Hermes bytecode and JS bundles are not a secure place to store secrets. Anyone who downloads your app can extract the key and run unlimited requests on your Anthropic bill.

This means every production React Native integration needs a server layer in between. You have three realistic options:

  1. Build your own backend (Node/Express, serverless functions, etc.) that holds the Anthropic key and exposes your own endpoints to the app.
  2. Use SubToAPI as that layer — it gives you an HTTPS endpoint with application-scoped sub_live_... keys, so the key embedded in your app's requests is never your Anthropic credential, and usage per key is visible in a dashboard.
  3. Some hybrid, where you proxy through SubToAPI and add your own thin middleware for business logic (rate limits per user, logging, auth).

Whichever you choose, the React Native side looks the same: it calls a backend over HTTPS, not Anthropic directly.

Basic request from a React Native screen

Here's a straightforward non-streaming call using fetch, pointed at a backend endpoint:

async function askClaude(prompt) {
  const response = await fetch('https://api.subtoapi.app/v1/messages', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${process.env.SUBTOAPI_KEY}`,
    },
    body: JSON.stringify({
      model: 'claude-sonnet-4-5',
      max_tokens: 1024,
      messages: [{ role: 'user', content: prompt }],
    }),
  });

  if (!response.ok) {
    throw new Error(`Request failed: ${response.status}`);
  }

  const data = await response.json();
  return data.content[0].text;
}

Important: never embed SUBTOAPI_KEY or an Anthropic key directly in the React Native bundle. In production, your mobile app should call your own backend route (which itself holds the key and forwards to SubToAPI or Anthropic), or at minimum use a server-issued short-lived token per user session. The snippet above is simplified for clarity — see /docs/quickstart for the full request/response shape.

Streaming responses on mobile

Chat-style UIs feel broken without streaming — users expect text to appear token by token. React Native's fetch doesn't support streaming response bodies the way browsers do, so you typically need one of:

A common pattern is to have your backend consume Claude's stream (see /docs/streaming) and re-emit it to the app over a WebSocket, since WebSocket support in React Native is solid and doesn't need extra polyfills:

const ws = new WebSocket('wss://your-backend.com/chat-stream');

ws.onopen = () => {
  ws.send(JSON.stringify({ prompt: userInput }));
};

ws.onmessage = (event) => {
  const chunk = JSON.parse(event.data);
  if (chunk.type === 'content_block_delta') {
    setReply((prev) => prev + chunk.delta.text);
  }
};

Your backend side subscribes to the Claude streaming endpoint and forwards each delta over the socket as it arrives. This keeps the mobile client simple and avoids fighting React Native's fetch limitations.

Handling tool use in a mobile UI

If your assistant needs to call tools — looking up order status, searching a database, hitting a weather API — the tool-calling loop still runs on your backend. The React Native app's job is to render intermediate states cleanly: "Checking your order...", a spinner, or a card showing the tool result once it comes back.

A simple state machine on the client works well:

const [status, setStatus] = useState('idle');
// 'idle' | 'thinking' | 'using_tool' | 'streaming' | 'done'

Your backend sends status events alongside content deltas so the UI can switch states without guessing. See /docs/tools for the request format tool definitions need to follow — the mobile app itself never needs to know about tool schemas, only about the status updates your backend chooses to surface.

Handling auth and user identity

Most React Native apps already have user auth (Firebase, Supabase, custom JWT). Attach the authenticated user's token to every request to your backend, and let the backend decide which application key to use when forwarding to Claude. This also lets you enforce per-user rate limits before you ever hit Anthropic's limits, and gives you a clean audit trail of which app user generated which request — useful when you're debugging cost spikes.

If you're using SubToAPI, each environment or app variant (iOS build, Android build, staging) can get its own sub_live_... key, so usage and billing are visible per surface in the dashboard rather than lumped into one Anthropic account. Plans start at €9/month for a single key (Solo), scaling to Team and Scale tiers with per-seat pricing for multiple developers managing keys — see /pricing.

Common pitfalls

Start with a working non-streaming integration end to end, confirm your auth and key handling are solid, then layer in streaming and tool use once the basic plumbing is proven. Check /docs for the full API reference once you're past the prototype stage.

Questions

Can I call the Claude API directly from React Native without a backend? Not safely in production. Any key in the app bundle is extractable. A backend (your own, or a service like SubToAPI) must hold the credentials and forward requests.

How do I stream Claude responses into a React Native chat UI? Have your backend consume the Claude stream and re-emit deltas to the app over WebSocket, since raw fetch-based streaming isn't reliably supported across React Native's networking stack.

Does SubToAPI work for both iOS and Android builds? Yes — it's a standard HTTPS API, so any platform that can make authenticated HTTP or WebSocket requests, including React Native on iOS and Android, can use it. See /docs/quickstart to get started.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →