Class 7 · CBSE AI · Strand B — Python for AI

How to use a language model via API — for Class 7

Send text, get a response: how to use an LLM through an API, and why tokens cost money. For Class 7.

What this concept actually says

  • An LLM API lets you send text and receive a generated response without running the model yourself
  • The prompt is your only interface to the model — prompt quality directly determines output quality
  • Temperature and other parameters control the randomness and style of the model's output

An analogy your child will recognise

STD phone booth

An API call is like making a trunk call from an STD booth. You dial a specific number (the API endpoint), speak your message (the prompt), and receive a response. You do not know or control the telephone exchange in between — you just know the protocol for sending and receiving.

Sending a letter to a government office

When you write to a government department, the format of your letter determines the quality of the response. A vague letter gets a vague reply. A specific, well-structured letter gets a specific, useful answer. LLM prompts work exactly the same way — the model is the department, your prompt is the letter.

Common misconceptions to watch for

  • Making more API calls always improves results — in reality, a single well-crafted prompt usually beats multiple poor prompts
  • The model 'understands' your prompt the way a human would — in reality, it processes statistical patterns in tokens and has no world model or intent

Key facts in one breath

  • LLM APIs typically charge by the number of tokens processed — both input and output tokens count towards cost
  • The system prompt sets the model's persona and constraints; the user prompt is the actual request
  • Temperature is usually between 0 and 2; most practical use cases fall between 0.2 and 0.8
  • API keys must be kept secret and never committed to public GitHub repositories — exposure can result in unexpected charges

How Dhee Learning teaches this — the 3-stage question loop

Every Dhee Learning session for this concept follows three stages. We share the questions Dhee actually asks, so you can hear what a session sounds like.

Stage 1 — Surface

You have been prompting AI tools all year. Now you are going to write Python code that sends a prompt and receives a response. What do you think is actually happening between your code and the AI model when you make that call?

Rote answer

"Your code sends the prompt to the API and gets a reply"

Understood

"Your code sends an HTTP request to a server running the model, the model processes your prompt token by token and generates a probability-weighted response, and that response is sent back as structured data your code can use"

Stage 2 — Reasoning

You set temperature=0.9 for a creative writing task and temperature=0.1 for a factual question-answering task. What would change in the output, and why might you want different settings for different tasks?

Follow-up Dhee may use: What would temperature=0 produce? What are the risks of that?

Stage 3 — Application

Write a Python function that takes a topic string and returns a 3-question quiz on that topic, generated by an LLM API. Test it on two different topics. How would you check whether the generated questions are actually good?

Misconception Dhee watches for: Trusting the API output uncritically because it came from a famous model — all LLMs can hallucinate, and using the output without verification is a serious risk

Related concepts

Want your child to actually understand this?

Dhee turns this concept into a 15-minute spoken session — asking, listening, and probing — so your child builds the idea themselves.

Frequently asked questions

What is using a pre-trained language model via api — explained for kids? +

Send text, get a response: how to use an LLM through an API, and why tokens cost money. For Class 7.

What's the most common mistake children make about this concept? +

Making more API calls always improves results — in reality, a single well-crafted prompt usually beats multiple poor prompts

How does Dhee Learning teach this in a Class 7 session? +

Dhee opens with a question — for example: "You have been prompting AI tools all year. Now you are going to write Python code that sends a prompt and receives a response. What do you think is actually happening between your code and the AI model when you make that call?" — listens to your child's answer, then probes the reasoning behind it. The session ends when the child can apply the idea to a brand-new situation, not just recall it.