---
title: Cloud Functions
description: >-
  Cloud Functions: getFunctions, connectFunctionsEmulator, httpsCallable with
  timeout and limitedUseAppCheckTokens options, httpsCallableFromUrl,
  callable.stream(), HttpsError / FunctionsError, HttpsErrorCode, SDK_VERSION,
  and region targeting.
next: /functions/writing-deploying-functions
previous: /firestore/pipelines/sdk-compatibility
---
> ## Documentation Index
> Fetch the complete documentation index at: https://rnfirebase.io/llms.txt
> Use this file to discover all available pages before exploring further.

## Prerequisites

- `@react-native-firebase/app` installed and native config completed per [Getting Started](/) (Android `google-services.json`, iOS `GoogleService-Info.plist`, Expo config plugin, or React Native CLI setup). From v26, New Architecture is required for packages with a native bridge.
- Install Functions: `npm install --save @react-native-firebase/functions` or `yarn add @react-native-firebase/functions`, then rebuild native apps (`cd ios && pod install` on iOS).
- Deploy HTTPS callable functions to your Firebase project, or run the Functions emulator (the Functions emulator listens on port `5001` by default). See [Writing & Deploying Functions](/functions/writing-deploying-functions).

Example Expo Router screen: https://github.com/invertase/react-native-firebase/blob/main/test-expo/app/functions.tsx

# Installation

This module requires that the `@react-native-firebase/app` module is already setup and installed. To install the "app" module, view the
[Getting Started](/) documentation.

```bash
# Install & setup the app module
yarn add @react-native-firebase/app

# Install the functions module
yarn add @react-native-firebase/functions

# If you're developing your app using iOS, run this command
cd ios/ && pod install
```

# Platform support and New Architecture

{/* prettier-ignore */}
| | |
| --- | --- |
| **Platforms** | Android, iOS (native Firebase SDK) |
| **New Architecture** | **Required** since v24 for Functions, and for all native modules from v26. See [Migrating to v26](/migrating-to-v26#new-architecture-requirement) and [Migrating to v24, Cloud Functions](/migrating-to-v24#cloud-functions). |

**Platform notes:** React Native Firebase exports `SDK_VERSION`, the runtime error class `HttpsError` (also aliased as `FunctionsError`), the `HttpsErrorCode` object, and the `HttpsErrorCodeValue` type for callable error codes without a `functions/` prefix (including RN-specific codes). The package type declarations also contain a legacy `FunctionsStatics` interface, but the package entry point does not export it. Each export is explained in the section that uses it.

# What does it do

Firebase Cloud Functions let you automatically run backend code in response to events triggered by Firebase features and
HTTPS requests. Your code is stored in Google's cloud and runs in a managed environment. There's no need to manage and
scale your own servers.

<YouTube id="vr0Gfvp5v1A" />

After you write and deploy a function, Google's servers begin to manage the function immediately. You can fire the function
directly with an HTTP request, via the Cloud Functions module, or in the case of background functions, Google's servers will listen for events and run
the function when it is triggered.

For more information on use cases, view the [Firebase Cloud Functions](https://firebase.google.com/docs/functions/use-cases) documentation.

# Usage

The Cloud Functions module provides the functionality to directly trigger deployed HTTPS callable functions, without worrying
about security or implementing a HTTP request library.

Functions deployed to Firebase have unique names, allowing you to easily identify which endpoint you wish to send a request to.
To learn more about deploying Functions to Firebase, view the [Writing & Deploying Functions](/functions/writing-deploying-functions) documentation.

## Emulator

Use `connectFunctionsEmulator` before any callable or stream calls when talking to the Local Emulator Suite (the Functions emulator listens on port `5001` by default). It throws if `port` is not a number.

On Android, `connectFunctionsEmulator` rewrites a host that starts with `localhost` or `127.0.0.1` to `10.0.2.2` (the host machine as seen from the Android emulator) and logs a message. Set `android_bypass_emulator_url_remap` to `true` in `firebase.json` to keep the host you pass (see [JSON Config](/app/json-config)). Use your machine's IP address when running on a physical device. The example below passes `10.0.2.2` explicitly on Android.

```js
import { Platform } from 'react-native';
import { connectFunctionsEmulator, getFunctions } from '@react-native-firebase/functions';

const host = Platform.OS === 'android' ? '10.0.2.2' : '127.0.0.1';
connectFunctionsEmulator(getFunctions(), host, 5001);
```

If your functions are deployed on a different region, pass that region to `getFunctions` before connecting (see [Region-specific Functions](/functions/usage#region-specific-functions)).

## Get a Functions instance

`getFunctions` returns a `Functions` instance for the default app and default region (`us-central1`). Pass a Firebase App and/or a region (or custom domain) when you need a non-default target:

```js
import { getApp } from '@react-native-firebase/app';
import { getFunctions } from '@react-native-firebase/functions';

const functions = getFunctions();
const europe = getFunctions(getApp(), 'europe-west1');
console.log('Default region instance app:', functions.app.name);
console.log('Europe instance app:', europe.app.name);
```

## Calling an endpoint

Assuming a deployed HTTPS callable named `listProducts`, call it with `httpsCallable`. The returned function takes an optional payload and resolves with `{ data }`:

```js
import { getFunctions, httpsCallable } from '@react-native-firebase/functions';

async function loadProducts() {
  const listProducts = httpsCallable(getFunctions(), 'listProducts');
  const response = await listProducts({ page: 1, limit: 15 });
  console.log('Products:', response.data);
}
```

Within a React Native component:

```jsx
import React, { useEffect, useState } from 'react';
import { Text } from 'react-native';
import { getFunctions, httpsCallable } from '@react-native-firebase/functions';

function ProductList() {
  const [loading, setLoading] = useState(true);
  const [productsJson, setProductsJson] = useState('');

  useEffect(() => {
    let cancelled = false;
    httpsCallable(getFunctions(), 'listProducts')()
      .then(response => {
        if (!cancelled) {
          setProductsJson(JSON.stringify(response.data));
          setLoading(false);
        }
      })
      .catch(error => {
        if (!cancelled) {
          console.log('Callable failed:', error);
          setLoading(false);
        }
      });
    return () => {
      cancelled = true;
    };
  }, []);

  if (loading) {
    return <Text>Loading…</Text>;
  }

  return <Text>{productsJson}</Text>;
}
```

Optional `HttpsCallableOptions` let you set a millisecond `timeout` (a non-numeric `timeout` throws) and `limitedUseAppCheckTokens`. Set `limitedUseAppCheckTokens` to `true` when the callable consumes App Check tokens for replay protection (see [Enable App Check enforcement for Cloud Functions](https://firebase.google.com/docs/app-check/cloud-functions)):

```js
import { getFunctions, httpsCallable } from '@react-native-firebase/functions';

const listProducts = httpsCallable(getFunctions(), 'listProducts', {
  timeout: 10_000,
  limitedUseAppCheckTokens: true,
});

async function loadWithOptions() {
  const response = await listProducts({ page: 1, limit: 15 });
  console.log('Products:', response.data);
}
```

## Call by URL

Use `httpsCallableFromUrl` when you have the full callable URL (for example a Cloud Run URL, or the emulator URL `http://HOST:PORT/PROJECT/REGION/NAME`). The firebase-js-sdk export is named `httpsCallableFromURL`; React Native Firebase uses `httpsCallableFromUrl`.

```js
import { Platform } from 'react-native';
import { getApp } from '@react-native-firebase/app';
import { getFunctions, httpsCallableFromUrl } from '@react-native-firebase/functions';

async function callByUrl() {
  const host = Platform.OS === 'android' ? '10.0.2.2' : '127.0.0.1';
  const projectId = getApp().options.projectId;
  const url = `http://${host}:5001/${projectId}/us-central1/listProducts`;
  const listProducts = httpsCallableFromUrl(getFunctions(), url);
  const response = await listProducts({ page: 1, limit: 15 });
  console.log('Products from URL:', response.data);
}
```

## Streaming results

Callable references returned by `httpsCallable` and `httpsCallableFromUrl` expose `.stream()`. It returns `{ stream, data }`: iterate `stream` for chunks as the backend calls `response.sendChunk()`, then await `data` for the final payload. If the function fails, iterating `stream` throws an `HttpsError` and `data` rejects with an `HttpsError`. The backend must be a callable that checks `request.acceptsStreaming` and calls `response.sendChunk()` (see [Writing & Deploying Functions](/functions/writing-deploying-functions#streaming-results)).

```js
import { getFunctions, httpsCallable } from '@react-native-firebase/functions';

async function listenToForecast() {
  const getForecast = httpsCallable(getFunctions(), 'getForecast');
  const { stream, data } = await getForecast.stream({
    locations: [{ latitude: 37.77, longitude: -122.41 }],
  });

  for await (const chunk of stream) {
    console.log('Forecast chunk:', chunk);
  }

  const allForecasts = await data;
  console.log('Final forecast payload:', allForecasts);
}
```

## Handle errors

When a callable throws an `HttpsError` on the server, the client rejects with an `HttpsError` instance (`code`, `message`, and optional `details`). If the server throws any other error, the client receives the code `internal`. React Native Firebase exports the client class as `HttpsError` and aliases it as `FunctionsError` (same constructor, so `FunctionsError === HttpsError`).

`HttpsErrorCode` is a React Native Firebase object of callable error code strings (uppercase keys such as `HttpsErrorCode.CANCELLED` and lowercase hyphenated keys such as `HttpsErrorCode['invalid-argument']`). The firebase-js-sdk does not export this helper from the modular `@firebase/functions` entry point. Runtime `code` values on `HttpsError` are lowercase strings without a `functions/` prefix, such as `invalid-argument`. The exported `HttpsErrorCodeValue` type lists the possible values (the standard codes plus `unsupported-type` and `failed-to-parse-wrapped-number`), although `error.code` itself is typed as `string` on the `HttpsError` class. A native code that is not recognized becomes `unknown`. The iOS-only codes `unsupported-type` and `failed-to-parse-wrapped-number` are reported when native iOS serialization rejects the request or response data.

The legacy `FunctionsStatics` interface describes the old `firebase.functions` statics shape that exposed `HttpsErrorCode`. The entry point does not export it, so import `HttpsErrorCode` from `@react-native-firebase/functions`.

```js
import {
  FunctionsError,
  HttpsError,
  HttpsErrorCode,
  getFunctions,
  httpsCallable,
} from '@react-native-firebase/functions';

async function callWithErrorHandling() {
  console.log('FunctionsError is HttpsError:', FunctionsError === HttpsError);
  console.log('cancelled code:', HttpsErrorCode.CANCELLED);

  const addMessage = httpsCallable(getFunctions(), 'addMessage');
  try {
    const result = await addMessage({ text: 'hello' });
    console.log('Message:', result.data);
  } catch (error) {
    if (error instanceof HttpsError) {
      console.log('code:', error.code);
      console.log('message:', error.message);
      console.log('details:', error.details);
      return;
    }
    console.log('Non-HttpsError:', error);
  }
}
```

## Region-specific Functions

If you deploy callables in a region other than `us-central1`, pass that region to `getFunctions` for both emulator connection and callable creation:

```js
import { Platform } from 'react-native';
import { getApp } from '@react-native-firebase/app';
import {
  connectFunctionsEmulator,
  getFunctions,
  httpsCallable,
} from '@react-native-firebase/functions';

const host = Platform.OS === 'android' ? '10.0.2.2' : '127.0.0.1';
const europe = getFunctions(getApp(), 'europe-west1');
connectFunctionsEmulator(europe, host, 5001);

async function callEuropeCallable() {
  const listProducts = httpsCallable(europe, 'listProducts');
  const response = await listProducts({ page: 1, limit: 15 });
  console.log('Europe products:', response.data);
}
```

## Package version

`SDK_VERSION` is the React Native Firebase Functions package version string exported from `@react-native-firebase/functions`. The firebase-js-sdk does not export `SDK_VERSION` from `@firebase/functions`.

```js
import { SDK_VERSION } from '@react-native-firebase/functions';

console.log('Functions package version:', SDK_VERSION);
```
