Build an AI Chat in Expo with React Native

Summary

Pixel shares a guide to adding a ChatGPT-style AI chat to an Expo app using the open-source react-native-ai-chat-kit. It covers a working mock chat, streaming responses, markdown, stop and retry controls, and connecting Anthropic, OpenAI, or Gemini models.

DEV Community

Add ChatGPT-style AI chat to your Expo app in 5 minutes

Almost every app wants an "Ask AI" screen now. Building one in React Native sounds easy until you hit the details: Text stutters while the response streams in, token by token Half-written markdown (**bold, an unclosed code block) breaks the layout fetch in React Native doesn't stream response bodies out of the box The keyboard covers the input on Android Then come stop, retry, chat history, file uploads... I rebuilt these one too many times, so I packaged them as an open-source library: react-native-ai-chat-kit. Here's how to add a full AI chat to an Expo app. 1. Create the app and install npx create-expo-app@latest my-ai-app --template blank-typescript
cd my-ai-app
npx expo install react-native-ai-chat-kit react-native-safe-area-context
The kit is pure TypeScript with no native code, so it runs in Expo Go and in React Native CLI apps. 2. A working chat, no API key needed Replace App.tsx: import { SafeAreaProvider, SafeAreaView } from 'react-native-safe-area-context';
import { ChatView, createMockTransport, useChat } from 'react-native-ai-chat-kit';

const transport = createMockTransport(); // a fake AI that streams demo answers

export default function App() {
const chat = useChat({ transport });
return (





);
}
Run npx expo start and open it in Expo Go. Tap a suggestion and watch a reply stream in with markdown, a table and a tool-call card. Stop, Retry and Copy already work. 3. Connect a real model Swap the mock for a provider. It's three lines: import { createProviderTransport } from 'react-native-ai-chat-kit';

const transport = createProviderTransport({
provider: 'anthropic', // or 'openai' | 'gemini'
apiKey: process.env.EXPO_PUBLIC_AI_KEY!,
model: 'claude-sonnet-5-5',
system: 'You are a friendly travel assistant.',
});
It also works with any OpenAI-compatible API (OpenRouter, Groq, Ollama...) through baseUrl. Never ship an API key inside an app. Anyone can pull it out of the bundle and spend your money. That's why createProviderTransport refuses to run in production builds. It's for prototyping. Step 4 is for real apps. 4. Go to production with the built-in server The package includes a server handler that keeps the key on your server. With Next.js on Vercel, it's one file: // app/api/chat/route.ts
import { createChatHandlerFromEnv } from 'react-native-ai-chat-kit/server';

const handler = createChatHandlerFromEnv(process.env);
export const POST = handler;
export const OPTIONS = handler;
Set AI_PROVIDER, AI_API_KEY and AI_MODEL in your Vercel project settings, then point the app at it: const transport = createStreamTransport({ url: 'https://your-app.vercel.app/api/chat' });
Switching from OpenAI to Claude is now a settings change. Templates for Cloudflare Workers and plain Node are in the repo. 5. Add chat history Swap useChat for useChatSessions and every conversation is saved. Users can reopen any chat and keep talking, with its full context: import AsyncStorage from '@react-native-async-storage/async-storage';
import { ChatHistory, createKeyValueStore, useChatSessions } from 'react-native-ai-chat-kit';

const store = createKeyValueStore(AsyncStorage);

const chat = useChatSessions({ transport, store, restoreLastSession: true, maxAgeDays: 30 });

// A ChatGPT-style list: Today, Yesterday, Previous 7 days... with search and delete

6. Photos, documents and voice npx expo install expo-image-picker expo-document-picker expo-image-manipulator expo-speech
import * as ImagePicker from 'expo-image-picker';
import * as DocumentPicker from 'expo-document-picker';
import * as ImageManipulator from 'expo-image-manipulator';
import * as ...
Build an AI Chat in Expo with React Native
Powered by Readybot.io

The latest from Pixel

Incident Response: Look Beyond the Red Alert

Pixel’s DEV Community announcement explores how teams can fixate on one failing service while overlooking the real cause of an outage, such as a full …

Sach: AI Fact-Checks WhatsApp Forwards in India

Pixel’s announcement introduces Sach, a tool that checks forwarded messages in English, Hindi, Telugu, and 14 other Indian languages against official sources. It gives cited …

Java 25 Removes SecurityManager: What to Fix

Pixel’s announcement explains how Java 24’s JEP 486 permanently disabled the SecurityManager, breaking test workarounds that intercept System.exit. It recommends returning exit codes or throwing …