← Blog

Claude API Mobile App Integration with React Native

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

Integrating Claude into a React Native app comes down to one architectural decision: you cannot call Anthropic's API directly from the mobile client. Every API key embedded in a mobile bundle can be extracted by anyone with a decompiler, so the real work isn't "how do I call Claude from React Native" — it's "how do I build a safe, fast proxy between my app and Claude, and how do I handle streaming on a mobile network."

This article walks through that pattern end to end: why a backend layer is mandatory, how to structure it, how to stream tokens into a React Native UI without jank, and how to handle tool use and errors on flaky mobile connections. The same pattern applies whether you're hitting the Anthropic API directly or routing through a gateway like SubToAPI.

Why a direct client-to-Claude call is a non-starter

Three concrete problems rule out calling api.anthropic.com directly from your app:

The fix is always the same: a thin backend (Node, Deno, Cloudflare Workers, whatever you already run) that holds the real credentials and exposes your own authenticated endpoint to the app. That backend either talks to Anthropic directly, or — if you don't want to build key rotation, usage tracking, and streaming infrastructure yourself — talks to a managed layer like SubToAPI, which turns your Claude access into a standard HTTPS API with its own application keys (sub_live_...), per-key usage metadata, and team seats.

Reference architecture

React Native app
   │  (your app's auth token)
   ▼
Your backend / edge function
   │  (SUBTOAPI_KEY, server-side only)
   ▼
SubToAPI → Claude

Your mobile app never sees a Claude or SubToAPI key. It only talks to your own backend using whatever auth you already use (Firebase, Supabase, a JWT, session cookies).

Backend endpoint

// server.js (Node/Express)
app.post("/api/chat", requireUser, async (req, res) => {
  const { messages } = req.body;

  const response = await fetch("https://api.subtoapi.app/v1/messages", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.SUBTOAPI_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      model: "claude-3-5-sonnet-latest",
      max_tokens: 1024,
      messages,
    }),
  });

  const data = await response.json();
  res.json(data);
});

See the full request shape in /docs/messages and the five-minute setup in /docs/quickstart.

Calling it from React Native

async function sendMessage(text) {
  const res = await fetch("https://your-backend.com/api/chat", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${userToken}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      messages: [{ role: "user", content: text }],
    }),
  });
  const data = await res.json();
  return data.content[0].text;
}

This is enough for a basic chat screen: one request, one response, render the text. The real complexity in mobile LLM apps is making responses feel fast — which means streaming.

Streaming into a React Native UI

A full response from Claude on a long answer can take several seconds. Without streaming, your UI sits on a spinner the whole time. With streaming, tokens appear as they're generated, which matters even more on mobile where users expect instant feedback.

React Native's fetch doesn't support readable streams the way browsers do, so the cleanest approach is a WebSocket or Server-Sent Events relay from your backend, or using a library like react-native-sse. Your backend requests streaming from the model exactly as documented in /docs/streaming, then forwards chunks to the client over a socket:

// backend: relay SSE chunks over a WebSocket
const upstream = await fetch("https://api.subtoapi.app/v1/messages", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.SUBTOAPI_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ model: "claude-3-5-sonnet-latest", stream: true, messages }),
});

for await (const chunk of upstream.body) {
  ws.send(chunk);
}

On the React Native side, append each incoming text delta to component state as it arrives:

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

This gives you the typing-style effect users expect from chat apps, with no heavy client-side SDK required.

Tool use for mobile features

If your app needs Claude to trigger actions — look up a user's order, fetch local data, call a device API — use tool calling instead of parsing free text. Define the tool schema on your backend, send it with the request as shown in /docs/tools, and handle the tool_use block by running your own function, then sending the result back in a follow-up message. Keep this logic entirely server-side; the mobile app just renders the final answer or a structured UI based on the tool result your backend returns.

Handling mobile-specific failure modes

Mobile networks drop connections mid-stream far more often than desktop broadband. Build for it:

Getting started

If you already have Claude access and just need an API layer your mobile backend can call without building key management yourself, sign up at /signup, generate an application key, and point your existing backend at the /v1/messages endpoint. Compare the Solo, Team, and Scale tiers on /pricing — Solo at €9 is enough for most single-app integrations, while Team and Scale add seats for a backend/mobile engineering team sharing one account.

Questions

Do I need a backend at all, or can React Native call Claude directly for a prototype? For a throwaway local demo on your own device, a hardcoded key technically works, but anything you distribute — TestFlight, Play Store internal testing, even a shared Expo link — exposes that key immediately. Build the proxy from day one.

How do I stream Claude responses on React Native without extra native modules? Relay Server-Sent Events through a WebSocket from your backend, since RN's fetch doesn't expose readable streams like browsers do. Your backend requests streaming normally and forwards each chunk over the socket to the app.

Can I use the same backend for both iOS and Android? Yes — the backend is platform-agnostic since it just exposes a REST/WebSocket endpoint your own auth protects. Both iOS and Android clients hit the same /api/chat route with no platform-specific logic needed.

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 →