> ## Documentation Index
> Fetch the complete documentation index at: https://docs.backapp.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Build a voice notes app

> Record audio, transcribe it, and show a user's note history with Backapp.

Build a mobile app that records a voice note, displays its transcript, and lets the user reopen it from their history. The mobile client records audio and renders the interface. Backapp handles device sessions, file storage, transcription jobs, and usage limits. You can add summaries with Text to Text and paid access with RevenueCat or Adapty.

## 1. Configure the app and plans

In the Backapp management panel, select your app under **Apps**. Add `speech_to_text` to **Allowed operations** and add `text_to_text` if you offer summaries. Preserve any existing operations. In **App credentials**, activate an OpenAI credential for the app.

In **Plans**, configure your allowances:

| User | Plan settings | Example |
| - | - | - |
| Unsubscribed | **free (non-subscribers)**, **fixed USD per period**, limit `0.10`, **lifetime** | Each user can try the app with a one-time $0.10 allowance. The default allowance without a free Plan is $0. |
| Subscribed | **paid**, **% of the price paid**, limit `50`, **monthly** | A $9 monthly subscription gives about $4.50 in AI usage per rolling monthly window. |

Backapp prorates percentage allowances using the recorded subscription period. The paid Plan applies across the app, including any enabled summary calls. The allowance is based on recorded estimated provider spend. Provider charges accrue to the account behind the configured credential. For a fixed \$4.50 monthly allowance regardless of subscription price, use **fixed USD per period**. See [App settings and usage limits](https://docs.backapp.dev/app-settings.md).

Choose **File retention hours** for source audio and **Job retention days** for saved transcripts. Give the recording enough time to survive upload, queueing, and any eligible retry. Set job retention to match how long users should see notes in their history. [File retention](https://docs.backapp.dev/files.md#app-retention-settings) · [Job retention](https://docs.backapp.dev/jobs.md)

## 2. Start a session on app launch

Recover the saved session at launch. Register on first launch or when a new session is needed. Generate a stable, random installation ID, such as a UUID, and save it in secure device storage. If the app supplies its own unique ID, it goes in the same `device_id` field (up to 128 characters). Use a high-entropy opaque value because Backapp uses it to recover the account. Keep it stable across launches and out of logs.

The curl examples use Bash and jq. Set `BACKAPP_APP_KEY`, `BACKAPP_APP_VERSION`, and `BACKAPP_DEVICE_ID` for your test installation. Run the snippets in the same shell.

```bash theme={"dark"}
api() {
  curl --fail-with-body --silent --show-error \
    -H "X-App-Key: $BACKAPP_APP_KEY" \
    -H "X-App-Version: $BACKAPP_APP_VERSION" "$@"
}

authed_api() {
  api -H "Authorization: Bearer $BACKAPP_ACCESS_TOKEN" "$@"
}

session=$(jq -n --arg id "$BACKAPP_DEVICE_ID" '{device_id: $id}' |
  api https://api.backapp.dev/v2/auth/device \
    -H 'Content-Type: application/json' --data-binary @-) &&
  BACKAPP_ACCESS_TOKEN=$(jq -er '.access_token' <<< "$session") &&
  BACKAPP_USER_ID=$(jq -er '.user_id' <<< "$session")
```

Store the returned access and refresh tokens securely. On access token expiry, call `POST /v2/auth/refresh` and replace the stored token pair. Use the same Backapp account and AppKey for upload, transcription, and history. A new installation ID can produce a new account and an empty history. See [Authentication](https://docs.backapp.dev/authentication.md).

## 3. Connect subscriptions (optional)

If you sell subscriptions, pass the Backapp `user_id` to your purchase SDK before purchase or restore. Configure the webhook for the same app and environment, then verify a sandbox purchase. Follow the [RevenueCat setup](https://docs.backapp.dev/integrations/revenuecat.md) or [Adapty setup](https://docs.backapp.dev/integrations/adapty.md).

After a purchase or restore, read `GET /v2/me` to confirm Backapp has received the new subscription state. Webhook delivery is asynchronous, so allow a short wait and recheck if the purchase succeeds but Backapp still shows the old state.

```bash theme={"dark"}
authed_api https://api.backapp.dev/v2/me | jq '.subscription'
```

## 4. Record, upload, and submit

Record after the user grants microphone permission. Finalize the recording locally before uploading. Speech to Text accepts MP3, M4A, or WAV, up to 22 MiB and 10 minutes per recording. This example uses `note.m4a`.

```bash theme={"dark"}
upload=$(authed_api https://api.backapp.dev/v2/files -F 'file=@note.m4a') &&
  BACKAPP_FILE_ID=$(jq -er '.file_id' <<< "$upload")
```

Keep the returned `file_id` and check `expires_at` before submitting. Send the ID to the transcription endpoint.

```bash theme={"dark"}
job=$(jq -n --arg file "$BACKAPP_FILE_ID" '{file_id: $file}' |
  authed_api https://api.backapp.dev/v2/transcriptions \
    -H 'Content-Type: application/json' --data-binary @-) &&
  BACKAPP_JOB_ID=$(jq -er '.job_id' <<< "$job")
```

HTTP 202 means Backapp accepted the submission and returned a job. Persist its `job_id` so the app can resume after a restart. If the response was lost, submit the same eligible `file_id` to recover the existing job while it exists and submission checks pass. If submission returns HTTP 402 `quota_exceeded`, explain the allowance and offer an upgrade if available. For HTTP 429 `too_many_active_jobs`, wait for an active job to finish before submitting again. See [Speech to Text](https://docs.backapp.dev/ai/speech-to-text.md) for full responses.

## 5. Display the transcript

Read the job with the persisted ID.

```bash theme={"dark"}
authed_api "https://api.backapp.dev/v2/transcriptions/$BACKAPP_JOB_ID"
```

While the app is in the foreground, start with a one-second interval between status checks while the job is `pending` or `processing`. Keep one request in flight, slow down if the job takes longer, and pause polling when the app goes into the background. Resume from the saved job ID when the app returns.

On `completed`, render `result.text`. On `failed`, stop polling and show an error. Offer a [job retry](https://docs.backapp.dev/jobs.md#retry-or-delete-a-job) when `error.retryable` is true. If the job returns HTTP 404, it may have expired or been deleted. Keep the source audio available until processing finishes.

## 6. Show note history

Use completed transcription jobs as the read-only note history. Render `created_at` and a preview of `result.text` for each row. Use `job_id` to open the full transcript.

```bash theme={"dark"}
history=$(authed_api --get https://api.backapp.dev/v2/jobs \
  --data-urlencode 'operation=speech_to_text' \
  --data-urlencode 'status=completed' \
  --data-urlencode 'limit=20') &&
  jq '{jobs, next_cursor}' <<< "$history"
```

Results are newest first and scoped to the current app and user. If `next_cursor` is a non-null string, repeat the same request with `--data-urlencode "cursor=$BACKAPP_NEXT_CURSOR"` after assigning the returned value to `BACKAPP_NEXT_CURSOR`. A null cursor marks the last page. History follows job retention, independently of source audio retention. For editable titles, tags, or links between notes and summaries, keep that metadata in the client for an installation-local experience.

## 7. Add an AI summary (optional)

When the user asks for a summary, select an available model from `GET /v2/texts/models` and assign its ID to `BACKAPP_MODEL_ID`. This example reads the completed transcript and generates a short summary in the request.

```bash theme={"dark"}
note=$(authed_api "https://api.backapp.dev/v2/transcriptions/$BACKAPP_JOB_ID") &&
  transcript=$(jq -er '. | select(.status == "completed") | .result.text' <<< "$note") &&
  summary=$(jq -n --arg prompt "$transcript" --arg model "$BACKAPP_MODEL_ID" \
    --arg id "$(uuidgen)" \
    '{model: $model, prompt: $prompt, request_id: $id, max_output_tokens: 256,
      instructions: "Summarize this voice note in three bullets. Include explicit action items."}' |
    authed_api https://api.backapp.dev/v2/texts/generations/sync \
      -H 'Content-Type: application/json' --data-binary @-) &&
  jq '{job_id, status, result, error}' <<< "$summary"
```

If `status` is `completed`, display `result.text`. If `result.truncated` is true, the summary may be incomplete. For longer work, use `POST /v2/texts/generations` and poll its job. Save the summary job ID against the transcription job ID in the client if you want to reopen the summary from a note. See [Text to Text](https://docs.backapp.dev/ai/text-to-text.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.