Skip to content

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

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.

  1. Publish the draft: POST /v1/posts/{ref}/publish. On 200, you are done.
  2. Classify the response with the table above. Only an SEO 422 with retryable: true enters the loop.
  3. Read the response: score_exact, minimum, shortfall, errors[] and reach_minimum_with. errors[] arrives sorted (vetoes first, then highest points_gain).
  4. Pick what to fix: every veto, plus the err values in reach_minimum_with (the smallest set covering the shortfall).
  5. Fix, in one of two ways:
    • Mechanical: apply fix.action to fix.target (insert_block, edit_block, edit_field, remove_block, rewrite_section); block_id says which block.
    • With a writer model: hand llm_prompt (pt or en) and the evidence to the model and ask for the fixed text.
  6. Write to the same post: PATCH /v1/posts/{ref} with the fixed content. Never create another post to retry.
  7. Publish again (step 1) and compare the new score_exact with the previous round’s.
  8. Stop when it publishes, when retryable is false, or when the budget runs out.

Suggested budget

  • At most 5 repair rounds per article.
  • Stop if score_exact does not rise in 2 consecutive rounds (the loop is spinning).
  • 429 and 503 have their own budget (for example 6 waits) and do not spend repair rounds.
  • When stopping, log the last score_exact and the remaining err values, 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.

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_id points to, with new, useful content. Use fix.action (rewrite_section, remove_block) or the llm_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.
  • PATCH is partial and repeatable; a repeated publish on a published post gives 409, which is not a failure.
  • Write one log line per round with: post_id, round, status, code, applied err values, score_exact before and after, shortfall, retryable, the wait applied and the trace_id (the response’s X-Request-Id header).
  • Keep the trace_id and the last score_exact on the article record: it is what support asks for in an incident. See Diagnosing failures.

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% jitter

The 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.

  1. ☐ The tool decides by status and code, never by free text.
  2. ☐ 422 with retryable: true enters the repair loop; it is not discarded.
  3. ☐ The same post is fixed by PATCH and published again; no attempt creates a new post.
  4. ☐ Budget: up to 5 rounds; stops when score_exact does not rise in 2 consecutive rounds.
  5. ☐ 429, 503 and 5xx wait Retry-After (or backoff) with jitter and do not spend a round.
  6. ☐ 503 does not change the article.
  7. ☐ Vetoes are resolved by rewriting or removing the section, never dressing it up.
  8. ☐ Each round writes a log with err, score_exact before and after, retryable and trace_id.
  9. ☐ When exhausted, the draft goes to a human with the reason logged.
  10. ☐ The model’s output is validated before the PATCH.
  1. publish → 200: done.
  2. 429 or 503 or 5xx: wait with jitter, repeat the same call (text unchanged).
  3. SEO 422 with retryable: false: stop, log, human.
  4. SEO 422 with retryable: true: fix vetoes and reach_minimum_with, PATCH the same post, back to step 1.
  5. score_exact not rising in 2 rounds, or 5 rounds spent: stop, log, human.
  6. Any other 4xx: fix the payload or key and log.

See also: SEO errors, Errors and rate limits, Chimpee guide and Rate limits.