Skip to main content
maintainx-cost-tuning Optimize MaintainX API usage for cost efficiency.
Use when managing API costs, optimizing request volume,
or implementing cost-effective integration patterns with MaintainX.
Trigger with phrases like "maintainx cost", "maintainx billing",
"reduce maintainx usage", "maintainx api costs", "maintainx optimization".
跳到安装 Skills Marketplace 发现并探索由社区构建的 Agent Skills
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/jeremylongshore/claude-code-plugins-plus-skills --skill maintainx-cost-tuning命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
下载 Zip 下载中... 同仓库更多 Skills Implement user sign-up and sign-in flows with Clerk.
Use when building authentication UI, customizing sign-in experience,
or implementing OAuth social login.
Trigger with phrases like "clerk sign-in", "clerk sign-up",
"clerk login flow", "clerk OAuth", "clerk social login".
Implement session management and middleware with Clerk.
Use when managing user sessions, configuring route protection,
or implementing token refresh and custom JWT templates.
Trigger with phrases like "clerk session", "clerk middleware",
"clerk route protection", "clerk token", "clerk JWT".
Configure enterprise SSO, role-based access control, and organization management.
Use when implementing SSO integration, configuring role-based permissions,
or setting up organization-level controls.
Trigger with phrases like "clerk SSO", "clerk RBAC",
"clerk enterprise", "clerk roles", "clerk permissions", "clerk organizations".
jeremylongshore
jeremylongshore/claude-code-plugins-plus-skills
打开 GitHub 仓库 name maintainx-cost-tuning description Optimize MaintainX API usage for cost efficiency.
Use when managing API costs, optimizing request volume,
or implementing cost-effective integration patterns with MaintainX.
Trigger with phrases like "maintainx cost", "maintainx billing",
"reduce maintainx usage", "maintainx api costs", "maintainx optimization".
allowed-tools Read, Write, Edit, Bash(npm:*) version 1.11.0 license MIT author Jeremy Longshore <jeremy@intentsolutions.io> tags ["saas","maintainx","api","cost-optimization"] compatibility Designed for Claude Code, also compatible with Codex and OpenClaw
MaintainX Cost Tuning
Overview
Reduce MaintainX API request volume and optimize costs through caching, webhook-driven sync, request batching, and smart polling strategies.
Prerequisites
MaintainX integration deployed and working
Redis or in-memory cache available
Baseline API usage metrics
Instructions
Step 1: Request Volume Tracking
class ApiUsageTracker {
private counts : Map <string , number > = new Map ();
private startTime = Date .now ();
record (endpoint : string ) {
const key = endpoint.split ('?' )[0 ];
this .counts .set (key, (this .counts .get (key) || 0 ) + 1 );
}
report ( ) {
const elapsed = (Date .now () - this .startTime ) / 1000 / 60 ;
console .log (`\n=== API Usage Report (${elapsed.toFixed( )} min) ===` );
sorted = [... . . ()]. ( b[ ] - a[ ]);
( [endpoint, count] sorted) {
rate = (count / elapsed). ( );
. ( );
}
. ( );
}
}
tracker = ();
( tracker. (), );
1
const
this
counts
entries
sort
(a, b ) =>
1
1
for
const
of
const
toFixed
1
console
log
` ${endpoint} : ${count} calls (${rate} /min)`
console
log
` TOTAL: ${[...this .counts.values()].reduce((a, b) => a + b, 0 )} calls`
export
const
new
ApiUsageTracker
setInterval
() =>
report
600_000
Step 2: Response Caching
interface CacheEntry <T> {
data : T;
expiresAt : number ;
}
class CachedMaintainXClient {
private cache = new Map <string , CacheEntry <any >>();
private client : MaintainXClient ;
private ttl : Record <string , number > = {
'/users' : 300 ,
'/locations' : 300 ,
'/assets' : 120 ,
'/workorders' : 30 ,
'/teams' : 600 ,
};
constructor (client : MaintainXClient ) {
this .client = client;
}
async get<T>(endpoint : string , params ?: any ): Promise <T> {
const cacheKey = `${endpoint} :${JSON .stringify(params || {})} ` ;
const cached = this .cache .get (cacheKey);
if (cached && cached.expiresAt > Date .now ()) {
console .log (`[CACHE HIT] ${endpoint} ` );
return cached.data ;
}
const basePath = '/' + endpoint.split ('/' ).filter (Boolean )[0 ];
const ttlSec = this .ttl [basePath] || 60 ;
const data = await this .client .request ('GET' , endpoint, undefined , params);
this .cache .set (cacheKey, {
data,
expiresAt : Date .now () + ttlSec * 1000 ,
});
tracker.record (endpoint);
return data as T;
}
invalidate (pattern : string ) {
for (const key of this .cache .keys ()) {
if (key.startsWith (pattern)) {
this .cache .delete (key);
}
}
}
}
Step 3: Webhook-Driven Sync (Replace Polling) Polling every 30 seconds costs thousands of requests/day per endpoint. Webhooks reduce this to near zero.
setInterval (async () => {
const { workOrders } = await client.getWorkOrders ({ status : 'OPEN' });
await syncToLocalDb (workOrders);
}, 30_000 );
app.post ('/webhooks/maintainx' , async (req, res) => {
const { event, data } = req.body ;
if (event === 'workorder.updated' || event === 'workorder.created' ) {
await upsertWorkOrder (data);
}
res.status (200 ).json ({ ok : true });
});
Cost savings : From thousands of daily polling requests to ~50 req/day (webhook-driven deltas only).
Step 4: Smart Polling with Conditional Requests When webhooks are not available, reduce unnecessary fetches:
async function smartPoll (client : MaintainXClient , state : { lastModified?: string } ) {
const response = await client.getWorkOrders ({
updatedAtGte : state.lastModified || new Date (0 ).toISOString (),
limit : 100 ,
});
if (response.workOrders .length === 0 ) {
console .log ('No changes since last poll' );
return [];
}
state.lastModified = new Date ().toISOString ();
return response.workOrders ;
}
Step 5: Request Deduplication
const inFlight = new Map <string , Promise <any >>();
async function deduplicatedGet (client : MaintainXClient , endpoint : string ): Promise <any > {
if (inFlight.has (endpoint)) {
return inFlight.get (endpoint)!;
}
const promise = client.request ('GET' , endpoint);
inFlight.set (endpoint, promise);
try {
return await promise;
} finally {
inFlight.delete (endpoint);
}
}
Output
API usage tracking with per-endpoint request counts
Response caching with resource-specific TTLs
Webhook-driven sync replacing expensive polling loops
Smart polling with updatedAtGte filter for change detection
Request deduplication preventing concurrent identical calls
Error Handling Issue Cause Solution Stale cache data TTL too long for volatile resources Reduce TTL for /workorders to 15-30s Webhook delivery failures Endpoint down or unreachable Fall back to polling with longer interval Cache memory growth No eviction policy Set max cache size, use LRU eviction Duplicate webhook events MaintainX retries Deduplicate by event ID (see webhooks skill)
Resources
Next Steps For architecture patterns, see maintainx-reference-architecture.
Examples Redis-based cache for production :
import Redis from 'ioredis' ;
const redis = new Redis (process.env .REDIS_URL );
async function cachedGet (key : string , ttlSec : number , fetcher : () => Promise <any > ) {
const cached = await redis.get (key);
if (cached) return JSON .parse (cached);
const data = await fetcher ();
await redis.setex (key, ttlSec, JSON .stringify (data));
return data;
}
const workOrders = await cachedGet (
'maintainx:workorders:open' ,
30 ,
() => client.getWorkOrders ({ status : 'OPEN' }),
);