{"uid":"cap_wVzzGmM6QwZt9HL1NnPE-","slug":"code-refactoring-agent-x402-mamenesia-e5cd1c0d","name":"Code Refactoring Agent (x402 / mamenesia)","description":"Pay-per-request AI developer tools in USDC on Base. Generate code, audit smart contracts, review diffs, summarize text, and convert data formats via the x402 payment standard. Powered by glm-5.2.","url":"https://code.mamenesia.com/service/refactor-code","method":"POST","headers":{},"bodySchema":{"type":"object","properties":{"prompt":{"type":"string","description":"Paste code + desired improvements"}}},"responseSchema":{"type":"json","example":{"paid":"3 USDC","result":{"code":"// generated output","model":"glm-5.1","tokens":100},"txHash":"0x...","service":"refactor-code"}},"example":null,"exampleRequest":null,"tags":["x402"],"displayCostAmount":"3","displayCostAsset":"USDC","priceDynamic":false,"priceHint":null,"priceStatus":"priced","priceSource":"probe","requiresHandshake":false,"reviewCount":0,"rating":{"score":"0.00","successRate":"0.00","reviews":0,"stars":null,"state":"unrated"},"availabilityStatus":"unknown","priceObserved":null,"sessionDeposit":null,"pricing":{"kind":"static","summary":"$3/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"3","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"3","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_FwKc9rBYQgSRibba5Y_hF","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"3","costPer":"request","priority":0,"asset":"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913","unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Refactors submitted source code based on specified improvement goals, returning cleaned and improved code powered by GLM-5.2, billed at $3 USDC per call via x402.","exampleAgentPrompt":"Can you refactor this Python function for me — it works but it's hard to read and has too much nesting: `def process(data): if data: for item in data: if item['active']: print(item['name'])` — I want it cleaner and more Pythonic.","exampleUseCases":[{"title":"Legacy code cleanup for readability","prompt":"I have this old PHP function that's a mess of nested conditionals and magic numbers — can you refactor it to be more readable and use named constants? Here's the code: `function calc($x,$y,$t){if($t==1){return $x*0.15+$y*2;}else{return $x*0.10+$y*1.5;}}`"},{"title":"JavaScript async refactor to modern style","prompt":"Refactor this callback-based JavaScript code to use async/await instead — it's a nightmare to follow: `fetchUser(id, function(err, user){ if(err){ handleError(err); } else { fetchOrders(user.id, function(err2, orders){ if(err2){ handleError(err2); } else { render(user, orders); }}); }});`"},{"title":"Apply SOLID principles to a Python class","prompt":"This Python class does way too many things at once — can you refactor it to follow the single responsibility principle? Here's the class: `class UserManager: def create_user(self, data): ... def send_welcome_email(self, user): ... def log_to_file(self, msg): ...`"}],"resultDescription":"Returns a JSON object containing the refactored code string, the model used (e.g. glm-5.1), token count consumed, the amount paid in USDC, the blockchain transaction hash for the payment, and the service name ('refactor-code').","failureModes":["Prompt too vague — no code provided, returns an error or unhelpful output","Payment failure — x402 transaction not confirmed, request rejected","Code too large — token limits exceeded, truncated or error response","Model unavailability — GLM backend offline, service returns 5xx","Malformed prompt — non-code text submitted, model returns nonsensical refactoring"],"whenToPreferThis":"Choose this endpoint when you need pay-per-use AI code refactoring without a subscription, especially in agent workflows that require on-demand code improvement billed transparently in USDC on Base. Prefer it over hosted LLM APIs when you want a single purpose-built refactoring endpoint with built-in micropayment settlement via the x402 protocol.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-09-15T06:39:46.890Z","isFirstParty":false}