Windsurf 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 Windsurf: mention the files, folders or functions involved so Cascade starts from the right place in your codebase. Below you'll find the prompt, how to run it in Windsurf, 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
- Files involved: [list the files, or reference them in the chat]
- How I build and test: [e.g. npm test]How to use this prompt
- 1
Open Windsurf
Open the Cascade panel in Windsurf and paste the prompt.
- 2
Give it context
Mention the files, folders or functions involved so Cascade starts from the right place in your codebase.
- 3
Review and iterate
Cascade can edit several files and suggest terminal commands. Review each change and command before you accept it.
- 4
Save what you repeat
Save conventions you repeat as rules so Cascade applies them without being told each time.
Working in Windsurf
- •Cascade acts on your workspace, so say which parts it must not touch.
- •Ask for a short plan before edits on anything larger than one file.
- •Run your tests after it finishes and paste failures back into the same conversation.
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.
- •Run your tests after it finishes and paste failures back into the same conversation.
- •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.
Will Windsurf change files on its own?
Cascade proposes edits and commands, and you review them. Asking for a plan first, as the prompt does, makes those changes easier to check.
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.