androidengineers.Book a session

Building the first request

Building the first request

articleSelf-paced

Make generation reproducible and observable.

1. Instructions and input

Keep task instructions separate from user-supplied text. Specify the desired answer and boundaries, then pass user content as data. A user message claiming to be a system update must not change application permissions.

2. Generation configuration

Set output limits and supported sampling settings deliberately. Record model identifier, prompt version and configuration with each evaluation run so changes can be compared.

3. Typed failures

Differentiate invalid input, unauthenticated requests, rate limits, service failures and blocked output. Show an actionable UI message without exposing backend credentials or raw internal errors.

Worked scenario

A travel question exceeds the allowed input size. The app rejects it locally and preserves the draft instead of repeatedly sending the same request.

Apply it

Implement a request adapter and a fake transport. Test a successful response, a missing candidate and a non-retryable input error.

Check your understanding

Every response shape maps to a domain result rather than a null crash. Explain the decision and show evidence from your implementation or design. If you cannot demonstrate it yet, revisit the relevant section before continuing.

YOUR LEARNING JOURNEY

0 of 13 available lessons completed

Progress saved in this browser. No account needed.
Building the first request | Gemini API for Android | Android Engineers