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 your code send a prompt and receive generated text without running the model yourself
  • The reply arrives as plain text, so your code must store it in a variable before any later line can use it
  • Both the prompt you send and the text that comes back are billed as tokens, and every call starts fresh

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.

Calling a translator-helpline on phone

You don't know Tamil. You call a translator helpline — speak in Hindi, get Tamil reply. The helpline (the API) does heavy work; you just connect. Using a language model via API is exactly this phone call.

Common misconceptions to watch for

  • The server remembers your earlier calls — in reality every call starts fresh, so anything the model needs must be sent again
  • Only the prompt you send is charged — in reality both the prompt and the text that comes back are counted as tokens

Key facts in one breath

  • LLM APIs typically charge by the number of tokens processed — both input and output tokens count towards cost
  • The reply is plain text: printing it shows it once, storing it in a variable keeps it for the rest of the program
  • An LLM API call is stateless — the server keeps nothing from your previous call, so earlier text must be sent again
  • 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

Your program must translate 500 short sentences. Would you make 500 separate API calls, or put many sentences into one call? What changes about time and cost?

Follow-up Dhee may use: If you split the work into one call per sentence, what does the server remember from sentence 1 when sentence 2 arrives?

Stage 3 — Application

Write a Python function that takes an English sentence and returns its Tamil translation from an LLM API. Print the reply AND store it. How would you check what that one call cost you?

Misconception Dhee watches for: Assuming the second call remembers the first — the child must send the earlier text again for any follow-up request

Related concepts

Want your child to actually understand this?

Dhee turns this concept into a short spoken lesson — teaching, listening, and probing — so your child builds the idea themselves.

Frequently asked questions

What is calling an llm from code — 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? +

The server remembers your earlier calls — in reality every call starts fresh, so anything the model needs must be sent again

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.