api-proxy-endpoint
What it does
This skill shows the AI agent how to create small server-side endpoints that hold API keys and serve a frontend. It is for developers who need outside data in a web app without exposing secret keys.
When to use it
- βWhen a frontend needs data from an external API that requires a secret key.
- βWhen you want one unified API path for a dashboard frontend.
- βWhen you deploy a serverless backend on Vercel and need CORS and error handling.
Skill link
https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/api-proxy-endpoint/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βMy dashboard needs stock and news data from paid APIs. Build proxy endpoints so the keys stay on the server.β
5 new skills a week. 1 minute to read.
How it works
The agent creates one file per API under an api folder, plus a shared helper for CORS headers. Each endpoint reads the key on the server, calls the outside API and returns the result to the frontend.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
API Proxy Endpoint Pattern
External APIs often require API keys that must not be exposed in frontend code. Create serverless proxy endpoints that:
- Hide API keys on the server side
- Provide a unified
/api/*namespace for the frontend - Handle CORS, rate limiting, and error wrapping
Endpoint Structure
Each API endpoint is a file in the api/ directory:
api/
βββ stocks.ts # Stock market data proxy
βββ news.ts # News API proxy
βββ calendar.ts # Calendar events proxy
βββ _cors.ts # Shared CORS helper
CORS Helper
// api/_cors.ts
export function corsHeaders() {
return {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type',
};
}
export function handleCors(req: Request): Response | null {
if (req.method === 'OPTIONS') {
return new Response(null, { status: 204, headers: corsHeaders() });
}
return null;
}
Example: Stock Proxy Endpoint
// api/stocks.ts
import type { VercelRequest, VercelResponse } from '@vercel/node';
export default async function handler(req: VercelRequest, res: VercelResponse) {
// CORS
res.setHeader('Access-Control-Allow-Origin', '*');
if (req.method === 'OPTIONS') return res.status(204).end();
const symbols = (req.query.symbols as string || '').split(',').filter(Boolean);
if (symbols.length === 0) {
return res.status(400).json({ error: 'Missing symbols parameter' });
}
const apiKey = process.env.FINNHUB_API_KEY;
if (!apiKey) {
return res.status(500).json({ error: 'API key not configured' });
}
try {
const quotes = await Promise.all(
symbols.map(async (sym) => {
const resp = await fetch(
`https://finnhub.io/api/v1/quote?symbol=${sym}&token=${apiKey}`
);
if (!resp.ok) throw new Error(`Finnhub ${resp.status}`);
const data = await resp.json();
return {
symbol: sym,
price: data.c, // current price
change: data.dp, // percent change
high: data.h,
low: data.l,
open: data.o,
prevClose: data.pc,
};
})
);
res.setHeader('Cache-Control', 's-maxage=30, stale-while-revalidate=60');
return res.json({ quotes });
} catch (err) {
console.error('Stock API error:', err);
return res.status(502).json({ error: 'Upstream API failed' });
}
}
Example: News Proxy Endpoint
// api/news.ts
import type { VercelRequest, VercelResponse } from '@vercel/node';
export default async function handler(req: VercelRequest, res: VercelResponse) {
res.setHeader('Access-Control-Allow-Origin', '*');
if (req.method === 'OPTIONS') return res.status(204).end();
const apiKey = process.env.NEWS_API_KEY;
if (!apiKey) return res.status(500).json({ error: 'API key not configured' });
const query = req.query.q as string || '';
const category = req.query.category as string || 'general';
const lang = req.query.lang as string || 'en';
try {
const url = query
? `https://gnews.io/api/v4/search?q=${encodeURIComponent(query)}&lang=${lang}&max=20&token=${apiKey}`
: `https://gnews.io/api/v4/top-headlines?category=${category}&lang=${lang}&max=20&token=${apiKey}`;
const resp = await fetch(url);
if (!resp.ok) throw new Error(`GNews ${resp.status}`);
const data = await resp.json();
res.setHeader('Cache-Control', 's-maxage=120, stale-while-revalidate=300');
return res.json({
articles: (data.articles || []).map((a: any) => ({
title: a.title,
description: a.description,
url: a.url,
source: a.source?.name || '',
publishedAt: a.publishedAt,
image: a.image,
})),
});
} catch (err) {
console.error('News API error:', err);
return res.status(502).json({ error: 'Upstream API failed' });
}
}
Key Patterns
- One file per API domain in the
api/directory - Always set CORS headers β frontend runs on different origin during dev
- Environment variables for API keys (
process.env.FINNHUB_API_KEY) - Cache-Control headers for edge caching (Vercel CDN)
- Error wrapping β return structured JSON errors, never raw upstream errors
- Input validation β validate query parameters before calling upstream
- Typed responses β keep response shapes consistent for frontend consumption
Local Deve
FAQ
Why not put the key in the frontend?
The skill says API keys must not be exposed in frontend code, so the proxy keeps them on the server.
What does the CORS helper do?
It sets the headers that allow the frontend to call the endpoints and answers preflight OPTIONS requests.
Which hosting is this designed for?
The skill is designed for Vercel serverless functions.
Details
Original description by the author
Create serverless API proxy endpoints that hide API keys and provide a unified backend for the dashboard frontend. Designed for Vercel deployment.
repo: HKUDS/AgentPilot
Popularity
- GitHub stars
- 7.8k
- Ranking position
- #13038
- License
- MIT
- Updated
- 11/1/2026
Comments
- β¦
More skills from this repository
agentpilot
7.8kHelps your agent improve a project step by step by preparing a task and running the AgentPilot loop that proposes, tests and scores changes.
openspace
7.8kHelps your agent set up OpenSpace, a tool that stores and fetches agent skills, and connect it to your AI app through MCP.
rsi-arena
7.8kHelps your agent set up and run standard AI benchmark tests, such as AIME and Terminal-Bench, to compare different improvement methods.
experiment-guide
7.8kHelps your agent plan small experiments, read their results and record findings while it investigates how to improve a program.
Similar skills
api-connector-builder
280kHas your agent build new API connections following the existing pattern. Use when you need to add one more integration without creating a new way of doing things.
api-design
280kHelps your agent design REST APIs following best practices. It's useful for defining how APIs communicate, how errors are shown, and how to organize data.
backend-patterns
280kHelps your agent with server-side architecture patterns and database optimization. It's useful for building or reviewing code that runs on the server.