Sub topic 2
Creating Your API Key
This chapter assumes you can use a command line, know basic Git, and understand what an HTTP API is. The previous chapter explained that an API key is a secret that identifies and authorizes your account. Here you will create one and store it safely at the moment it is shown.
What you need before you start
Provider consoles differ in layout, but the flow is similar. You need:
- An account with the LLM provider, usually verified by email.
- A billing method or credit balance, if the provider charges for API use. API billing is often separate from any chat subscription you hold.
- A place to put the key right away, such as a password manager.
The creation flow
Follow these steps in your provider's console. Menu names vary, so check the provider's documentation if a label differs.
- Sign in and find the section named something like "API keys" or "Credentials".
- Choose the option to create a new key.
- Give it a name that says what it is for, such as
blog-summarizer-dev. A good name helps you find the right key to revoke later. - If the console offers a project, permission set, or expiry date, pick the narrowest option that works. A later chapter covers scoping in detail.
- Copy the key when the console shows it.
- Save it in a password manager before you close the dialog.
Why the key is shown only once
Most providers display the full key a single time. Afterward the console shows only a short prefix or the last few characters. The provider keeps a hashed form of the key, not the key itself, so it cannot show it to you again.
If you close the dialog without saving the key, you cannot recover it. Delete that key and create a new one.
What a key looks like
Keys are long random strings, often with a provider-specific prefix. A made-up example:
sk-example-4f8a1c9e7b2d6035aa91Do not use this value. It is an illustration only. Your provider's real keys are longer and follow their own format, which is useful later when scanning tools need to recognize them.
Naming and keeping track
Create one key per application and per environment from the start. A short table in your password manager entry or notes helps:
| Key name | Used by | Environment |
|---|---|---|
| `summarizer-dev` | Your laptop | Development |
| `summarizer-ci` | Test pipeline | CI |
| `summarizer-prod` | Deployed service | Production |
Separate keys mean you can revoke one without breaking the others. They also show you which application is responsible for spend.
Confirming the key exists
After saving the key, check that the console lists it under the name you chose, with its prefix or last characters visible. Compare those characters against your stored copy. Do not test the key yet. A later chapter shows how to verify it without printing it.
Common mistakes
- Closing the dialog before copying. Delete the key and make a new one.
- Copying extra whitespace. A trailing space or newline makes the key invalid. If requests fail with an authentication error, check for stray characters first.
- Reusing one key everywhere. One leak then affects every project.
- Saving the key in a plain notes file inside your project folder. That file can be committed by accident.
Exercise
You created a key, closed the dialog, and realized you did not copy it. What should you do, and why?
Show answer
Delete that key in the console and create a new one. The provider stores only a hashed form, so it cannot show the original again. Save the new key in a password manager before closing the dialog.