Handling publish refusals
This guide is for anyone publishing articles through the API, such as Chimpee and any other integration.
It exists because of a misreading: a tool treated the refusal “score 85 below the minimum 85” as terminal and let the
article die without trying to fix it. A refusal is never that. Today it is an RFC 9457
422 that says what is missing, where and how to fix it, as data. The dictionary of every err is in
SEO errors (and, as a machine file, in /seo-errors.json).
1. Decision table
Section titled “1. Decision table”Decide by the HTTP status and, inside it, by the code field. Do not parse detail.
| Status | code |
Meaning | Action |
|---|---|---|---|
422 |
SEO_SCORE_BELOW_MINIMUM |
The exact score (score_exact) is below minimum. shortfall is missing. |
Repair loop: fix errors[] (start with reach_minimum_with), PATCH, publish again. |
422 |
SEO_STRUCTURAL_VETO |
The score may be high, but a veto is active (blocks_publish: true, err 2xx or 902). |
Rewrite the section named in block_id. Points do not offset a veto. See section 3. |
503 |
SEO_SCORE_UNVERIFIABLE |
The SEO engine is down (err 901). The text was not rejected; nothing was published. | Do not change the article. Wait Retry-After (with jitter) and repeat the same call. |
429 |
rate_limited |
The key’s request limit. | Wait Retry-After and repeat. It does not spend a repair round. |
5xx |
upstream or no body |
Transient server failure. | Exponential backoff with jitter, up to 3 attempts; then log and postpone the article. |
Validation 4xx (400, 422 unprocessable, INVALID_FOCUS_KEYWORD…) |
varies | The payload is wrong, not the SEO. | Fix the field the error names and resend. If the same error repeats, stop and log. |
401, 403 |
unauthorized, forbidden |
Missing, revoked or under-scoped key. | Terminal for the tool: ask the operator for a correct key. |
409 |
NOT_PUBLISHABLE |
The post is already live (or archived). | Do not repeat. Read the post state. |
Mind the 503 code: the HTTP response code is SEO_SCORE_UNVERIFIABLE. Inside errors[] the entry has err: 901.
Decide by the status and the response code, or by the err number, never by text.
2. The repair loop, step by step
Section titled “2. The repair loop, step by step”- Publish the draft:
POST /v1/posts/{ref}/publish. On200, you are done. - Classify the response with the table above. Only an SEO
422withretryable: trueenters the loop. - Read the response:
score_exact,minimum,shortfall,errors[]andreach_minimum_with.errors[]arrives sorted (vetoes first, then highestpoints_gain). - Pick what to fix: every veto, plus the
errvalues inreach_minimum_with(the smallest set covering the shortfall). - Fix, in one of two ways:
- Mechanical: apply
fix.actiontofix.target(insert_block,edit_block,edit_field,remove_block,rewrite_section);block_idsays which block. - With a writer model: hand
llm_prompt(ptoren) and theevidenceto the model and ask for the fixed text.
- Mechanical: apply
- Write to the same post:
PATCH /v1/posts/{ref}with the fixed content. Never create another post to retry. - Publish again (step 1) and compare the new
score_exactwith the previous round’s. - Stop when it publishes, when
retryableisfalse, or when the budget runs out.
Suggested budget
- At most 5 repair rounds per article.
- Stop if
score_exactdoes not rise in 2 consecutive rounds (the loop is spinning). 429and503have their own budget (for example 6 waits) and do not spend repair rounds.- When stopping, log the last
score_exactand the remainingerrvalues, and hand the draft to a human. The draft stays saved.
Backoff with jitter for 429, 503 and 5xx: wait Retry-After seconds when the header exists; without it, use
min(60, 2^attempt) seconds. Add random jitter of 0 to 25% so several instances do not come back together.
3. Vetoes (err 2xx and 902)
Section titled “3. Vetoes (err 2xx and 902)”A veto (blocks_publish: true, points_gain: 0) blocks even with a score of 100. Examples: empty section (210), subheading that repeats
its parent (211), duplicate headings (212), duplicate content (213), leaked markup (214), boilerplate filler (215), repeated sources (216).
- Rewrite the section the
block_idpoints to, with new, useful content. Usefix.action(rewrite_section,remove_block) or thellm_prompt. - Never “dress it up” to pass: swapping a word, adding an empty sentence or hiding the passage lowers quality and the veto returns next round. If the section has nothing to say, remove it.
- If the veto persists after the rewrite, stop and hand it to a human: it is not a score problem.
4. Idempotency and traceability
Section titled “4. Idempotency and traceability”PATCHis partial and repeatable; a repeatedpublishon a published post gives409, which is not a failure.- Write one log line per round with:
post_id,round,status,code, appliederrvalues,score_exactbefore and after,shortfall,retryable, the wait applied and thetrace_id(the response’sX-Request-Idheader). - Keep the
trace_idand the lastscore_exacton the article record: it is what support asks for in an incident. See Diagnosing failures.
5. Sample code
Section titled “5. Sample code”Hosts are fictional (.example); use your own API host. The key comes from the environment, never from code.
TypeScript: full loop with mechanical fixes
Section titled “TypeScript: full loop with mechanical fixes”const BASE = "https://api.canverly.example";const H = { Authorization: `Bearer ${process.env.CANVERLY_API_KEY}`, "Content-Type": "application/json" };const MAX_RODADAS = 5, MAX_ESPERAS = 6;
type Erro = { err: number; code: string; blocks_publish: boolean; block_id: string | null; evidence?: string; fix: { action: string; target: string }; llm_prompt: { pt: string; en: string } };type Post = { title: string; excerpt: string; blocks_json: unknown; focus_keyword?: unknown };
const dorme = (s: number) => new Promise((r) => setTimeout(r, s * 1000));const espera = (r: Response, n: number) => (Number(r.headers.get("Retry-After")) || Math.min(60, 2 ** n)) * (1 + Math.random() * 0.25);
async function publicarComReparo(ref: string, post: Post, corrigir: (p: Post, e: Erro[]) => Promise<Post>) { let ultimo = -1, semGanho = 0, esperas = 0; for (let rodada = 1; rodada <= MAX_RODADAS; ) { const r = await fetch(`${BASE}/v1/posts/${ref}/publish`, { method: "POST", headers: H }); const trace = r.headers.get("X-Request-Id"); if (r.ok || r.status === 409) return { ok: true, rodada };
if ([429, 503].includes(r.status) || r.status >= 500) { // transient: does not spend a round if (++esperas > MAX_ESPERAS) return { ok: false, motivo: "wait budget exhausted", trace }; await dorme(espera(r, esperas)); continue; // same call, same article } const c = await r.json().catch(() => null); const seo = r.status === 422 && ["SEO_SCORE_BELOW_MINIMUM", "SEO_STRUCTURAL_VETO"].includes(c?.code); if (!seo) return { ok: false, motivo: `${r.status} ${c?.code ?? ""}`, trace }; // validation/auth: not SEO if (!c.retryable) return { ok: false, motivo: "retryable=false", trace };
semGanho = c.score_exact > ultimo ? 0 : semGanho + 1; // stop when there is no progress console.log(JSON.stringify({ ref, rodada, code: c.code, score_exact: c.score_exact, shortfall: c.shortfall, err: c.errors.map((e: Erro) => e.err), trace })); if (semGanho >= 2) return { ok: false, motivo: "no gain in 2 rounds", trace }; ultimo = c.score_exact;
const alvo = new Set<number>(c.reach_minimum_with); // vetoes + smallest set covering the shortfall const lista = c.errors.filter((e: Erro) => alvo.has(e.err) || e.blocks_publish); post = await corrigir(post, lista.length ? lista : c.errors); await fetch(`${BASE}/v1/posts/${ref}`, { method: "PATCH", headers: H, body: JSON.stringify(post) }); // SAME post rodada++; } return { ok: false, motivo: "round budget exhausted" };}
// Mechanical fix: one if/else (or switch) per fix.action.async function corrigirMecanico(post: Post, erros: Erro[]): Promise<Post> { for (const e of erros) { switch (e.fix.action) { case "insert_block": post = inserirBloco(post, e.fix.target, e); break; case "edit_block": post = editarBloco(post, e.block_id, e); break; case "edit_field": post = editarCampo(post, e.fix.target, e); break; case "remove_block": post = removerBloco(post, e.block_id); break; case "rewrite_section": post = await reescreverSecao(post, e.block_id, e); break; } } return post; // insertBlock-style helpers (inserirBloco, editarBloco...) are yours, one per action}Python: fixes by a writer model (from llm_prompt)
Section titled “Python: fixes by a writer model (from llm_prompt)”import json, random
def corrigir_com_llm(post: dict, erros: list[dict], idioma: str = "pt") -> dict: """Builds ONE request with every instruction and returns the fixed post.""" instrucoes = [] for e in erros: trecho = e.get("evidence") or "" alvo = f"block {e['block_id']}" if e.get("block_id") else e["fix"]["target"] instrucoes.append(f"- [{e['err']}] {alvo}: {e['llm_prompt'][idioma]} Excerpt: {trecho}") pedido = ( "Fix the article below applying ONLY these instructions. Do not invent data, " "do not hide passages and keep what is already right. Return the complete JSON.\n\n" + "\n".join(instrucoes) + "\n\nArticle:\n" + json.dumps(post, ensure_ascii=False) ) return json.loads(chamar_modelo(pedido)) # chamar_modelo: your own LLM client
def esperar(resp, n: int) -> float: base = float(resp.headers.get("Retry-After") or min(60, 2 ** n)) return base * (1 + random.random() * 0.25) # 0 to 25% jitterThe loop skeleton (publish → classify → fix → PATCH on the same post) is the TypeScript one above; swap
corrigirMecanico for corrigir_com_llm. Always validate the model’s output (valid JSON, intact blocks_json, no open [VERIFICAR])
before the PATCH, and check the fixes did not remove links, sources or blocks that were not the target.
6. Integration checklist
Section titled “6. Integration checklist”- ☐ The tool decides by status and
code, never by free text. - ☐
422withretryable: trueenters the repair loop; it is not discarded. - ☐ The same post is fixed by
PATCHand published again; no attempt creates a new post. - ☐ Budget: up to 5 rounds; stops when
score_exactdoes not rise in 2 consecutive rounds. - ☐
429,503and5xxwaitRetry-After(or backoff) with jitter and do not spend a round. - ☐
503does not change the article. - ☐ Vetoes are resolved by rewriting or removing the section, never dressing it up.
- ☐ Each round writes a log with
err,score_exactbefore and after,retryableandtrace_id. - ☐ When exhausted, the draft goes to a human with the reason logged.
- ☐ The model’s output is validated before the
PATCH.
Flow summary
Section titled “Flow summary”publish→200: done.429or503or5xx: wait with jitter, repeat the same call (text unchanged).- SEO
422withretryable: false: stop, log, human. - SEO
422withretryable: true: fix vetoes andreach_minimum_with,PATCHthe same post, back to step 1. score_exactnot rising in 2 rounds, or 5 rounds spent: stop, log, human.- Any other
4xx: fix the payload or key and log.
See also: SEO errors, Errors and rate limits, Chimpee guide and Rate limits.