androidengineers.Book a session

The very basics

Prompts, responses, and APIs

article6 min

Using an LLM always comes down to the same exchange: you send it a prompt, and it sends back a response.

Prompt and response

  • Prompt: everything you give the model — your question, instructions, examples, documents to read.
  • Response: what the model writes back. Also called the output, completion, or generation.
Prompt:    "Explain what an API is to a 10-year-old, in two sentences."
Response:  "An API is like a waiter in a restaurant: you tell it what you want,
            and it brings it back from the kitchen. Apps use APIs to ask other
            programs for information or help."

The way you write a prompt changes the response a lot. Clear, specific prompts get better answers — that skill is sometimes called prompt engineering.

How apps talk to models: APIs

When you use a chat app, you type into a website. When your own app uses a model, it sends a request over the internet to the model provider's API (Application Programming Interface) — a defined way for programs to talk to each other.

Your app  ──── request: model name + prompt + settings ───▶  Provider's API
Your app  ◀─── response: generated text + token usage ─────  Provider's API

A request is usually a small piece of JSON like this:

{
  "model": "a-model-name",
  "messages": [{"role": "user", "content": "Explain what an API is in two sentences."}],
  "max_output_tokens": 200
}

Each provider's exact format is a little different, and most offer official libraries (SDKs) so you don't write the JSON by hand. The idea is the same everywhere.

API keys: keep them secret

To use a provider's API, you sign up and get an API key — a long secret string that identifies you and your bill. Every request includes it.

Treat an API key like a password:

  • Never put it in a public code repository.
  • Never put it inside a mobile app or website code that users can download — anyone could extract it and run up your bill.
  • Keep it on your server, and have your app talk to your server.

For Android apps, services such as Firebase AI Logic exist partly to solve this: they let your app call models without shipping a secret key inside the app.

You pay per use

Most model APIs charge per token (small chunks of text — the next module explains them). You pay for the tokens you send and the tokens the model writes. Many providers have a free tier for learning, so you can experiment for little or no cost.

Quick check: why shouldn't you put your API key inside your Android app's code? (Anyone can extract it from the app and use your account — keep keys on a server.)

YOUR LEARNING JOURNEY

0 of 15 available lessons completed

Progress saved in this browser. No account needed.