api-response-optimization · secondsky — Claude Code skill: faster API responses
A coding-agent skill that walks through payload trimming, HTTP caching and compression for API endpoints. Useful when responses feel slow.
npx skills add secondsky/claude-skills --skill api-response-optimization -a claude-codeWhat api-response-optimization does
The skill covers three areas: sparse fieldsets, HTTP caching and response compression. Each comes with a JavaScript example. Sparse fieldsets let a client ask for specific columns through a fields query parameter. Caching relies on ETag and Cache-Control headers, and a matching if-none-match returns 304 with no body.
Compression is wired up with the compression package, a filter that checks the x-no-compression header and level 6. There is a checklist too: drop unnecessary fields, add ETag/Last-Modified, turn on gzip or brotli, paginate collections, eager-load relations to avoid N+1 queries, and watch metrics through APM tools. Performance targets are listed as well, such as a response under 100ms instead of 500ms.
One piece of advice stands out: profile before optimizing. Skip that step and you may compress the wrong part of the request path while CPU usage climbs. Aggressive caching belongs on immutable resources only; frequently changing data needs a short TTL and cache invalidation on writes.
What it helps with
- shrink JSON responses by returning only requested fields
- add ETag support so repeat requests get a 304
- turn on gzip or brotli for responses over 1KB
- kill N+1 queries with eager loading
- build a pre-release checklist for an endpoint
Example prompts for the agent
- add sparse fieldsets to this endpoint
- set up ETag and Cache-Control for the product route
- check these API responses for N+1 and tell me what to cache
How to install api-response-optimization
1Skills CLI (Vercel)
npx skills add secondsky/claude-skills --skill api-response-optimization -a claude-code2Manually: put the files in place
~/.claude/skills/api-response-optimization/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/api-response-optimization/
1Skills CLI (Vercel)
npx skills add secondsky/claude-skills --skill api-response-optimization -a codex2Manually: put the files in place
.agents/skills/api-response-optimization/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add secondsky/claude-skills --skill api-response-optimization -a cursor2Manually: put the files in place
.cursor/skills/api-response-optimization/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install secondsky/claude-skills api-response-optimization2Manually: put the files in place
.github/skills/api-response-optimization/SKILL.md1Skills CLI (Vercel)
npx skills add secondsky/claude-skills --skill api-response-optimization -a gemini-cli2Platform CLI
gemini skills install https://github.com/secondsky/claude-skills --path plugins/api-response-optimization/skills/api-response-optimizationManually: put the files in place
.devin/skills/api-response-optimization/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add secondsky/claude-skills --skill api-response-optimization -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about api-response-optimization
How do I install api-response-optimization in Claude?
Run npx skills add secondsky/claude-skills --skill api-response-optimization -a claude-code. The skill file then lands at ~/.claude/skills/api-response-optimization/SKILL.md.
What does api-response-optimization do?
It shows how to cut response payloads, configure HTTP caching and enable compression, with code samples and an optimization checklist.
Which platforms support the skill?
Beyond Claude it installs into Codex, Cursor, GitHub Copilot, Gemini CLI and OpenCode, each with its own install command.
Source text
SKILL.md · MIT
---
name: api-response-optimization
description: Optimizes API performance through payload reduction, caching strategies, and compression techniques. Use when improving API response times, reducing bandwidth usage, or implementing efficient caching.
license: MIT
---
# API Response Optimization
Reduce payload sizes, implement caching, and enable compression for faster APIs.
## Sparse Fieldsets
```javascript
// Allow clients to select fields: GET /users?fields=id,name,email
app.get('/users', async (req, res) => {
const fields = req.query.fields?.split(',') || null;
const users = await User.find({}, fields?.join(' '));
res.json(users);
});
```
## HTTP Caching Headers
```javascript
app.get('/products/:id', async (req, res) => {
const product = await Product.findById(req.params.id);
const etag = crypto.createHash('md5').update(JSON.stringify(product)).digest('hex');
if (req.headers['if-none-match'] === etag) {
return res.status(304).end();
}
res.set({
'Cache-Control': 'public, max-age=3600',
'ETag': etag
});
res.json(product);
});
```
## Response Compression
```javascript
const compression = require('compression');
app.use(compression({
filter: (req, res) => {
if (req.headers['x-no-compression']) return false;
return compression.filter(req, res);
},
level: 6 // Balance between speed and compression
}));
```
## Performance Targets
| Metric | Target |
|--------|--------|
| Response time | <100ms (from 500ms) |
| Payload size | <50KB (from 500KB) |
| Server CPU | <30% (from 80%) |
## Optimization Checklist
- [ ] Remove sensitive/unnecessary fields from responses
- [ ] Implement sparse fieldsets
- [ ] Add ETag/Last-Modified headers
- [ ] Enable gzip/brotli compression
- [ ] Use pagination for collections
- [ ] Eager load to prevent N+1 queries
- [ ] Monitor with APM tools
## Best Practices
- Cache immutable resources aggressively
- Use short TTL for frequently changing data
- Invalidate cache on writes
- Compress responses >1KB
- Profile before optimizing
© secondsky · MIT · secondsky/claude-skills
Similar skills
Everything for Backend and APIs →api-response-optimization by other authors comes first.