# Code Refactoring Agent (x402 / mamenesia)

> Code Refactoring Agent (x402 / mamenesia) is a paid API for AI agents from code.mamenesia.com, paid per call via x402, $3/call, status unknown (last checked 2026-09-15).

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.

## Facts

- Endpoint: POST https://code.mamenesia.com/service/refactor-code
- Price: $3/call
- Payment: x402
- Status: unknown
- Last checked: 2026-09-15
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/code-refactoring-agent-x402-mamenesia-e5cd1c0d
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_wVzzGmM6QwZt9HL1NnPE-

Status and success rate cover calls made through Zero and Zero's own probes. Third-party monitors may report differently.

## How to call it through Zero

Zero handles the 402 payment challenge and records the run. With the Zero CLI installed (`npm i -g @zeroxyz/cli`):

```sh
zero fetch --capability code-refactoring-agent-x402-mamenesia-e5cd1c0d -d '<json body>'
```

Example prompt: 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.

## When to prefer this

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.

## Known failure modes

- 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

## How this service works

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.

## Output

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').

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "properties": {
  "prompt": {
   "type": "string",
   "description": "Paste code + desired improvements"
  }
 }
}
```

## Response schema (JSON Schema)

```json
{
 "type": "json",
 "example": {
  "paid": "3 USDC",
  "result": {
   "code": "// generated output",
   "model": "glm-5.1",
   "tokens": 100
  },
  "txHash": "0x...",
  "service": "refactor-code"
 }
}
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/code-refactoring-agent-x402-mamenesia-e5cd1c0d/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from code.mamenesia.com](https://www.zero.xyz/host/code.mamenesia.com/llms.txt)
