Intermediate level · Module 4: External API Integration · Lesson 3 of 3
Caching, Rate Limits and Credentials
Learners cache API responses to save bandwidth and money, respect rate limits including Retry-After, and handle API credentials with minimal scopes.
In this lesson you will
- Cache API responses appropriately
- Respect rate limits and protect credentials
Key concepts
response cachingtime-to-liveHTTP 429 and Retry-AfterAPI key scopescredential rotation
The lesson
Many agent questions repeat the same lookups. Caching responses (for example in SQLite with a time-to-live of one hour for prices) saves bandwidth, money and time, which matters on slow or expensive connections. Do not cache personal data longer than necessary.
When an API returns 429 (too many requests), read the Retry-After header if present and wait that long. Also limit your own request rate so that you stay within the provider's limits.
Use API keys with the narrowest permissions available (read-only where possible), keep them in environment variables, and rotate them if they are exposed.
Step by step
- Add a SQLite cache with a time-to-live to the price tool.
- Measure the requests saved over 50 repeated questions.
- Handle 429 with Retry-After in the mock API.
- Write the credential policy for the project.
Practice activity
Add caching and rate-limit handling to the API tool and write a credential policy.
Expected result: Fewer requests through caching, correct 429 handling and a clear credential policy.
Check your understanding
-
Why cache API responses in agent tools?
Show answer
To save bandwidth, money and time on repeated lookups.
-
What does the Retry-After header tell you?
Show answer
How long to wait before retrying after a rate-limit response.
Further learning
Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.