← Table of Contents · Page 32 of 868
FROM MODEL TO APPLICATION
Part 2 of 11
APPLICATION PROGRAMMING INTERFACES
An API is a doorway that lets one piece of software ask another piece of software to do something, following agreed rules.
The best everyday comparison is a restaurant.
You, the customer, do not walk into the kitchen and cook.
Instead you look at a menu, tell the waiter what you want in an agreed way, and the waiter brings back the dish.
The menu and the way you order are the interface.
The kitchen can change how it cooks without you caring, as long as the menu and ordering process stay the same.
A model API works the same way.
The company that runs the model keeps it on powerful computers.
Your program sends a request that follows the provider's rules, and the provider sends back a response.
You never touch the model's internals.
In practice, most requests travel over the internet using Hypertext Transfer Protocol Secure (HTTPS), which is the standard, encrypted way that programs and web browsers exchange messages.
The request is usually sent to an address called an endpoint, which is a specific web address that accepts a certain kind of request.
The request carries a few parts.
First, there is an authentication detail, usually a secret string called an API key that proves who is making the request and lets the provider bill the right account.
You must guard an API key like a password, never pasting it into chats or public code.
Second, there is the name of the model you want to use.
Third, there is the content you want the model to work on.
Fourth, there are optional settings such as temperature, which you met in Chapter 2, and a limit on how many tokens the model may write.
The data in the request and response is typically written in JavaScript Object Notation (JSON), a plain-text format for organizing information in labeled pairs, which both people and programs can read easily.
A tiny piece of JSON might say that a field called "model" has the value "example-model" and a field called "temperature" has the value 0.
Because everything travels as plain text, any programming language can create these requests.
Many providers also offer SDKs, which are ready-made code libraries that handle the details of sending requests so that you write fewer lines.
Advertisement
Read Aloud:
0:00 / 0:00