Skip to main content
Build a mobile app that lets users enter text, choose languages and a model, and reopen their translations. Use synchronous generation for short text and background generation for longer passages.

1. Set up the app and session

In the management panel, add text_to_text to Allowed operations and activate an OpenAI credential. If unsubscribed users should be able to translate text, configure a positive free Plan. Register the device with a stable installation ID. Set BACKAPP_APP_KEY, BACKAPP_APP_VERSION, and BACKAPP_ACCESS_TOKEN. Keep the same app and user session for generation, polling, and history. Run the Bash, curl, and jq snippets in the same shell.

2. Choose languages and a model

Offer source and target language pickers in the app. For an Auto-detect source option, tell the model to detect the source language in the instructions. Choose the target explicitly. Backapp accepts the languages in instructions and the original text in prompt. Populate language labels from your app’s supported choices. Fetch the model catalog when the user opens the translator. Use the full model ID from the response and check its max_output_tokens. If your UI offers a reasoning setting, use only values listed in the model’s reasoning_efforts.
The output limit above is for this short example. Choose a larger limit for longer passages within the selected model’s advertised maximum. The combined prompt and instructions can contain up to 3,000,000 characters, subject to the model’s context limit.
Generate a fresh request_id for each new translation. Keep that ID and the payload together so you can resend the same request if the response is lost. Both routes share request IDs for the same app and user. The examples use different IDs to run both flows independently.

3. Translate short text in the request (sync)

HTTP 200 returns the job object. Check status before displaying the translation because the job may have failed. A reused request ID can return a job that is still pending or processing. Poll its job_id as shown below. The sync route uses a 90-second provider timeout.

4. Translate longer text in the background (async)

HTTP 202 returns a job, typically pending for a new submission. Save its job_id so the user can leave the screen and return while the translation runs.
Poll with a delay while the job is pending or processing. Keep one status request in flight and stop when the job reaches completed or failed. If the user leaves the app, resume from the saved job ID when they return.

5. Display the translation

Both flows return the translation in result.text when status is completed. Render it as plain text and preserve line breaks. The example uses the sync response. Use async_result for a completed background job.
If result.truncated is true, label the translation as incomplete. To try again, use a higher output limit within the model’s cap or split the source into smaller passages, with a new request ID for each new generation. For failed jobs, read error.code and offer a job retry when error.retryable is true. For HTTP 402 quota_exceeded, explain the usage limit and show an upgrade option if available. For model_not_available, refresh the catalog. See Text to Text for full response examples.

6. Show translation history

List completed Text to Text jobs for the current user and app. This pulls in both sync and async translations. Show a preview of result.text and the creation date. Reopen an entry with the same status endpoint and its job_id.
Results are newest first. For the next page, pass the returned next_cursor as cursor with the same filters. A null cursor marks the last page. History follows the app’s Job retention days setting. If your app also uses Text to Text for other features, keep the translation job IDs in the client to identify translations. You can also save source and target language labels alongside those IDs for display. See Jobs.