← Blog

Claude API in React Native: Mobile App Integration

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

Adding Claude to a React Native app means answering one question first: where does the Anthropic API key live? It cannot live in your app bundle. Mobile apps are distributed as compiled binaries that anyone can decompile, inspect, or intercept traffic from, so any key shipped inside the app — hardcoded, in .env, in AsyncStorage — is public within hours of release. The fix is a thin backend layer between your React Native UI and Claude, either one you build yourself or a hosted proxy you plug in with a drop-in key.

This guide covers the architecture, the React Native-specific gotchas (streaming on iOS/Android, token limits on mobile networks, background/foreground state), and working code for both a custom Node proxy and a managed option.

Why you can't call Claude directly from the app

Anthropic's API expects an x-api-key header tied to your account's billing and rate limits. If that key is embedded in a mobile build:

The standard architecture is:

React Native app → your backend (or a proxy) → Claude API

Your backend holds the real credentials, applies auth/rate limiting for your own users, and forwards requests. The app only ever talks to an endpoint you control over HTTPS.

Option 1: Build your own proxy

A minimal Express proxy looks like this:

// server.js
const express = require("express");
const Anthropic = require("@anthropic-ai/sdk");

const app = express();
app.use(express.json());

const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });

app.post("/chat", async (req, res) => {
  const { messages } = req.body;
  // TODO: verify the calling user (JWT, session, etc.) before proceeding
  const response = await anthropic.messages.create({
    model: "claude-opus-4",
    max_tokens: 1024,
    messages,
  });
  res.json(response);
});

app.listen(3000);

This works, but you now own: deployment, uptime, streaming infrastructure, per-user usage tracking, retries on 429s, and key rotation. For a side project that's fine. For a shipping product with real users, it's a maintenance line item you'll revisit every time Anthropic changes rate limits or releases a new model.

Option 2: Use a hosted API layer

SubToAPI exists for exactly this gap: it turns your Claude access into a clean HTTPS API with application keys (sub_live_...), streaming, tool use, and usage metadata per key — so your React Native app calls a stable endpoint instead of managing its own backend proxy infrastructure from scratch.

// api.js - called from your React Native app
const SUBTOAPI_KEY = "sub_live_..."; // stored on YOUR server, not in the app

export async function askClaude(messages) {
  const res = await fetch("https://api.subtoapi.app/v1/messages", {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${SUBTOAPI_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      model: "claude-opus-4",
      max_tokens: 1024,
      messages,
    }),
  });
  return res.json();
}

The important detail: even with SubToAPI, the sub_live_... key stays on a server you control — a serverless function, a lightweight Node service, or your existing backend. Your React Native app calls that endpoint, which forwards to SubToAPI. You still need one network hop between the app and the key, but you no longer need to build message formatting, streaming, or usage tracking yourself. See the quickstart and messages endpoint docs for the full request/response shape.

Streaming responses in React Native

Claude's chat UX depends on streaming tokens as they're generated. React Native's fetch doesn't expose a readable stream the same way browsers do, so most teams use one of two approaches:

Server-Sent Events via react-native-sse or a polyfill, reading chunks as they arrive and appending to a message state variable.

A WebSocket bridge, where your backend streams Claude's output over a socket connection the app subscribes to — more reliable across iOS background/foreground transitions than raw SSE.

import EventSource from "react-native-sse";

const es = new EventSource("https://your-backend.com/chat-stream", {
  method: "POST",
  body: JSON.stringify({ messages }),
});

es.addEventListener("message", (event) => {
  const chunk = JSON.parse(event.data);
  setReply((prev) => prev + chunk.text);
});

es.addEventListener("error", () => es.close());

SubToAPI's streaming docs cover the event format your backend receives from the proxy, which you then re-emit to the app in whatever transport fits your stack.

Mobile-specific things to handle

Minimal checklist before shipping

Whether you build the proxy yourself or use a service like SubToAPI (plans start at €9/month with a free trial at signup), the architecture is the same: React Native talks to your backend, your backend talks to Claude. That boundary is what keeps your API key — and your bill — safe.

Questions

Can I call the Claude API directly from a React Native app without a backend? Not safely. Any API key bundled in a mobile app can be extracted. You need at least one server-side hop that holds the real credentials.

How do I stream Claude responses into a React Native chat UI? Use Server-Sent Events (via a library like react-native-sse) or a WebSocket bridge from your backend, appending text chunks to message state as they arrive.

Is SubToAPI a replacement for Anthropic's API? No — it's a layer on top of your existing Claude access that gives you application API keys, streaming, and usage tracking so you don't have to build that infrastructure yourself. See the docs for details.

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 →