{"uid":"cap_jJQQSgs1iEw9rh6StfXrd","slug":"context-preparation-api-v1-clean-d4b1d45e","name":"Context Preparation API – /v1/clean","description":"Deterministic multi-format cleaning, safety inspection, structural chunking, hybrid ranking, contradiction checks, and target-model token packing for AI agents.","url":"https://nexus-x402-ff2a.onrender.com/v1/clean","method":"POST","headers":{},"bodySchema":{"type":"object","properties":{"redact":{"type":"boolean","description":"Defaults to true for /prepare and false for other operations."},"target":{"type":"object"},"content":{"type":"string"},"question":{"type":"string"},"documents":{"type":"array"},"maxTokens":{"type":"integer"},"chunkTokens":{"type":"integer"},"queryEmbedding":{"type":"array"}}},"responseSchema":{"type":"object","required":["operation","content","chunks","warnings","safety","metrics","target"],"properties":{"chunks":{"type":"array","items":{"type":"object"}},"safety":{"type":"array","items":{"type":"object"}},"target":{"type":"object"},"content":{"type":"string"},"metrics":{"type":"object"},"warnings":{"type":"array","items":{"type":"object"}},"operation":{"enum":["clean","inspect","pack","prepare"]},"potentialContradictions":{"type":"array","items":{"type":"object"}}}},"example":null,"exampleRequest":null,"tags":["x402"],"displayCostAmount":"0.0005","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":"$0.0005/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.0005","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.0005","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_in7pgnxWRCrcKA39UwRrP","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.0005","costPer":"request","priority":0,"asset":"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913","unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Cleans, safety-inspects, structurally chunks, hybrid-ranks, contradiction-checks, and token-packs text or documents for consumption by a target AI model.","exampleAgentPrompt":"Clean and safety-inspect this 3,000-word document, chunk it into 256-token segments, rank the chunks against my question 'What are the key risks?', and pack the top results into a 2,048-token budget for GPT-4o — also flag any contradictions and redact PII.","exampleUseCases":[{"title":"RAG pipeline context packing","prompt":"I have 12 research articles and I need to answer the question 'What are the long-term effects of sleep deprivation?' — clean all the documents, chunk them into 200-token pieces, rank by relevance, and pack the best chunks into a 4,096-token window for my Claude model."},{"title":"Safety gate before LLM call","prompt":"Before I send this user-submitted forum post to my chatbot, run a safety inspection on it and flag anything harmful or policy-violating — I need the safety results and any warnings back so I can decide whether to proceed."},{"title":"Contradiction detection across sources","prompt":"I've got three analyst reports that may disagree with each other — can you clean and parse all three, then surface any contradictions between them so I can review them before my AI summarizer runs?"}],"resultDescription":"Returns a JSON object with the operation type ('clean', 'inspect', 'pack', or 'prepare'), the cleaned/transformed content string, an array of structured chunks, a safety array with flagged issues, a warnings array, a metrics object (token counts, ranking scores), target model metadata, and an optional potentialContradictions array listing conflicting passages across input documents.","failureModes":["Missing required 'content' or 'documents' field returns a validation error","Token budget (maxTokens) too small to fit even a single chunk may return empty chunks array","Invalid or unsupported target model spec may cause target metadata to be null or empty","Malformed query embedding array causes ranking step to fail or be skipped","Very large documents exceeding service limits may result in truncation or a 413 error","Network timeout on render.com cold-start instances may cause initial latency spikes"],"whenToPreferThis":"Choose this endpoint when you need a deterministic, multi-step preprocessing pipeline — cleaning, safety inspection, chunking, ranking, contradiction detection, and token packing — in a single call, rather than stitching together separate utilities. Ideal for RAG pipelines, multi-document QA agents, or any workflow where raw text must be safely and precisely prepared before being handed to a downstream LLM within a strict token budget.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-09-16T00:38:32.201Z","isFirstParty":false}