AI API: the request is an interface to a hosted computation
An application programming interface (API) lets software request an operation from another system. An AI API can accept messages and return generated content while the provider handles model execution.
The interface hides hardware details, not the application's choices. You still select the model, construct context, set an output budget and decide what to do with the response.
Call a model from Python
Install huggingface_hub, set HF_TOKEN and choose a provider-supported chat model in HF_MODEL. This example uses the documented InferenceClient chat interface.
import os
from huggingface_hub import InferenceClient
client = InferenceClient(token=os.environ["HF_TOKEN"])
response = client.chat_completion(
model=os.environ["HF_MODEL"],
messages=[{"role": "user", "content": "Explain why the sky is blue in two sentences."}],
max_tokens=128,
)
answer = response.choices[0].message.content
A streaming response delivers output pieces as they become available; it does not make the model finish computing the whole answer first. Tools and structured outputs add protocols around the generated content.
Do not assume the service retains a conversation just because the client object persists. The endpoint's contract determines whether you resend messages or reference stored state. Authentication, quotas and retention are also properties of that service, not of the language-model architecture.