A tool definition and what it costs
The characters-per-token rule is a rough estimate (Topic 1.2). Your provider's usage field gives the real count.
The model chooses and fills in tools using only their names, descriptions and JSON Schema parameters. Clear names, descriptions that say when to use the tool, and tight schemas (types, enums, required fields) are the main way to make tool use reliable.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 6 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write make_tool(name, description, properties, required) that returns the tool definition dict in the API shape, and print its function name.
Write tokens_estimate(tools) that returns the estimated tokens of a list of tool dicts as the length of their compact JSON divided by 4 (integer division).
Explain it without notes
What does the model actually see of a tool, and what follows for how you write them?
How do enum, required and description on a parameter each reduce errors?
What is the cost of a long tool list and how do you keep it under control?
Expected output
{"type":"function","function":{"name":"get_weather","description":"Get the current weather for a city. Use it for questions about temperature or sky today.","parameters":{"type":"object","properties":{"city":{"type":"string","description":"City name, for example Pune"},"unit":{"type":"string","enum":["celsius","fahrenheit"],"description":"Temperature unit. Default celsius."}},"required":["city"]}}}
required: city
characters: 401
about 100 tokens, sent with every request