How it works

An API (Application Programming Interface) is a contract between two systems. It defines what requests one program can make to another, in what format, and what is returned. In the AI context, a provider's API lets your code send a prompt and receive the model's response without running the model locally.

Communication typically uses HTTP: you send a request with parameters such as model, messages, temperature, and you receive a response in JSON. Every call requires authentication, usually via an API key.

Practical example

A simple call to a chat API:

Terminal
curl https://api.exemplo.com/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-4o","messages":[{"role":"user","content":"Olá"}]}'

The response includes the generated text, the number of tokens used, and the stop reason. Your code reads this JSON and displays or processes the result.

What it's for

APIs are used to integrate AI models into apps, websites, and automations without managing inference infrastructure. They are the most common way to use AI in production. Knowledge of APIs, endpoints, authentication, rate limits, and error handling is essential for anyone building AI products.