Amazon Q API Integration Prompt Template
You get working client code for a specific API call that handles auth, errors, timeouts and pagination the way the real API behaves. This version is set up for Amazon Q: name the AWS services, regions and resources involved, and paste the relevant code or configuration. Below you'll find the prompt, how to run it in Amazon Q, a worked example and answers to common questions.
Help me integrate with an external API.
## The API
Name and endpoint: [e.g. GitHub REST API, GET /users/{username}/repos]
Auth method: [e.g. bearer token in an env var, none]
Relevant docs or sample response: [paste the docs section or a real JSON response]
## My setup
Language and runtime: [e.g. Node 20 with built-in fetch]
Where this runs: [e.g. serverless function, background job]
## What I need
[e.g. a function that returns repo names and star counts for a user]
## Instructions
- Base field names on the docs or sample response I gave. If you are unsure of a field, say so instead of inventing it.
- Read secrets from environment variables, never hardcode them.
- Handle: non-2xx responses, timeouts, rate limits and empty results.
- Mention pagination if the endpoint paginates.
## Output format
1. The function, ready to paste
2. An example call and its expected return value
3. A list of errors the caller should expect
Context
- Reference material: [paste it below, or attach the file]How to use this prompt
- 1
Open Amazon Q
Open Amazon Q in your IDE or the AWS console and paste the prompt.
- 2
Give it context
Name the AWS services, regions and resources involved, and paste the relevant code or configuration.
- 3
Review and iterate
Ask follow-ups in the same chat, and test changes in a non-production account first.
Working in Amazon Q
- •Amazon Q is built for AWS work, so name the services (for example Lambda, S3, IAM) your question involves.
- •Never paste credentials or secret values; describe the IAM setup instead.
- •For infrastructure changes, ask for the change as code (CloudFormation, CDK or Terraform) so you can review it.
Worked example
What you give it
API: GitHub REST API, GET /users/{username}/repos
Auth: none for public repos
Runtime: Node 20, built-in fetch
Where it runs: a serverless function behind our team dashboard.
Need: a function that returns name and star count for each public repo. Return an empty list if the user does not exist.What a good answer looks like (shortened)
1. Function:
export async function listRepos(username) {
const url = "https://api.github.com/users/" + encodeURIComponent(username) + "/repos?per_page=100";
const res = await fetch(url, {
headers: { Accept: "application/vnd.github+json" },
signal: AbortSignal.timeout(10000),
});
if (res.status === 404) return [];
if (!res.ok) throw new Error("GitHub API error " + res.status);
const repos = await res.json();
return repos.map((r) => ({ name: r.name, stars: r.stargazers_count }));
}
2. listRepos("octocat") returns objects shaped like { name: "Hello-World", stars: 1234 }, one per public repo.
3. Errors: 403 or 429 when the unauthenticated rate limit is hit, a TimeoutError after 10 seconds. Users with more than 100 repos need pagination using the Link response header.Tips for better results
- •A real JSON response in the docs section is the single best input. It removes guessing about field names, nesting and types.
- •Say where the code runs in My setup. A serverless function needs short timeouts and no long retry loops, while a background job can retry more.
- •Never paste credentials or secret values; describe the IAM setup instead.
- •Avoid this: Not pasting the docs or a sample response, so the AI guesses field names that look right but do not exist.
Get the free prompt pack
Our best coding prompts in one Markdown file, delivered by email. The templates here stay free either way — the pack just saves you the copying.
Variations
Build an endpoint instead
Replace What I need with: An HTTP endpoint in [framework] that accepts [request shape] and returns [response shape], with input validation.
Add retries
Add this line to Instructions: Retry 429 and 5xx responses up to 3 times with exponential backoff, and respect a Retry-After header if present.
Typed client
Add this line to Output format: 4. TypeScript types for the request and response, based only on the sample response.
Save it as a Retext snippet
Retext is a free text expander for Mac. Save this prompt once, then type ;apiint in any app (ChatGPT, Claude, your editor, a browser tab) and the full prompt is pasted in.
- Click Add to Retext. The prompt installs as a snippet with the trigger ;apiint.
- Change the trigger in Retext if you prefer a different one.
- Type the trigger wherever you want the prompt, then fill in the brackets.
Frequently asked questions
Why does AI-generated API code use fields that do not exist?
Without docs it fills gaps from similar APIs it has seen. Paste the relevant docs section or one real response, and ask it to flag any field it is unsure of.
Is this prompt only for AWS projects?
Amazon Q is most useful when the work involves AWS services. The prompt still works for general code, but say what stack you use.
Should I paste my API key so the AI can test the call?
No. Use a placeholder like process.env.API_KEY in the prompt. The code should read the key from the environment anyway.
How do I reuse this prompt without copying it every time?
Click Add to Retext to save it as a snippet. Then type ;apiint in any Mac app, including your AI tool, and the full prompt is pasted in.
Related Templates
Get the free prompt pack
Our best coding prompts in one Markdown file, delivered by email. The templates here stay free either way — the pack just saves you the copying.