LLM APIs and Structured Output
Call a hosted model from code, handle failures and cost, and turn free-form text into validated data your program can trust.
What an LLM API call is
A hosted model is an HTTP service. You send a request with messages and settings; you get back text and usage numbers. Providers differ in names and extras, but the shape is the same.
| Request field | Meaning |
|---|---|
| model | Which model to run; price and quality differ |
| messages | System, user and assistant turns (see the prompting lesson) |
| temperature | Randomness of sampling |
| max tokens | Hard limit on output length |
| stop sequences | Strings that end generation |
| tools / schema | Optional: tool definitions or an output format (provider specific) |
| Response field | Why you care |
|---|---|
| text | The answer, as a string |
| usage | Input and output token counts, which set the bill |
| finish reason | Stopped naturally, hit max tokens (output may be cut off), or other |
1 of 8