Use AI models (Cloud Functions)
Run AI models in your mobile app through Firebase Cloud Functions and OpenRouter.
This feature lets users chat with AI models inside the app. The mobile client calls Firebase Cloud Functions in functions/. Those functions call the model provider and return the response.
You need a Firebase project with Cloud Functions enabled. See Firebase for project setup.
How it works
- The app sends a prompt from the Ask AI tab.
- A Cloud Function in
functions/receives the request. - The function calls your model provider and streams or returns the answer.
By default the kit uses OpenRouter with a single API key. One key can reach DeepSeek, GPT, Claude, Gemini, and other models OpenRouter exposes. You can switch to direct provider keys later if you prefer.
1. Configure functions/
cp functions/.env.example functions/.envSet your OpenRouter key:
# OpenRouter API key (single key for every model)
# Get yours at: https://openrouter.ai/keys
OPENROUTER_API_KEY=Deploy or run the functions so the app can reach them.
2. Local functions (optional)
While developing, point the app at a local functions server:
EXPO_PUBLIC_USE_LOCAL_FUNCTIONS_SERVER=truePut that in .env.local at the project root. Rebuild the native app after changing this flag.
3. Custom providers
OpenRouter is the default so you do not need separate keys per model. If you want to call a provider directly instead, update the functions code and env in functions/ to match that provider. Keep secrets in functions/.env, never in the mobile app bundle.
Related
- Firebase: Auth, Firestore, and enabling Cloud Functions
- Customize AI rules: coding-agent rules for your product
- Feature flags: turn product surfaces on or off