KAKUNIN

Errors

Error codes, shapes, and how to handle them.

Error Shape

All errors return a consistent JSON body:

{ "error": "Human-readable error message" }

Never parse the error string — use the HTTP status code for logic. The string is for humans and logging.

HTTP Status Codes

CodeNameWhen it happens
400Bad RequestMissing required fields, invalid JSON, failed Zod validation
401UnauthorizedMissing Authorization header, invalid API key, revoked key
403ForbiddenKey exists but lacks permission for this operation
404Not FoundResource doesn't exist or isn't in your tenant scope
409ConflictDuplicate — e.g. certifying an agent that already has an active cert
422UnprocessableValid input but illegal state — e.g. certifying a retired agent
425Too EarlyReport is still generating — poll again
429Rate LimitedAPI key exceeded rate limit — see Retry-After header
500Internal ErrorUnexpected server error — contact support
503Service UnavailableDependency unavailable (e.g. KMS not configured)

Common Errors by Endpoint

Certificate issuance (POST /v1/agents/{id}/certify)

Statuserror messageFix
404Agent not foundCheck agent ID and tenant scope
409Agent already has an active certificateRevoke existing cert first
422Cannot certify a retired agentStatus must be pending or active
503KMS not configuredAWS credentials missing — contact support

Certificate revocation (POST /v1/certificates/{id}/revoke)

Statuserror messageFix
404Certificate not foundCheck cert ID
409Certificate is already revokedAlready done
422Certificate has expiredCannot revoke an expired cert

Event ingest (POST /v1/events)

Statuserror messageFix
400Invalid action_typeMust be one of the 8 supported types
404Agent not foundAgent ID not in your tenant
422Agent is not activeOnly active (certified) agents can ingest events

Rate Limit Headers

When rate limited (429), the response includes:

X-RateLimit-Limit: 100
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1716040800000
Retry-After: 42

Retry-After is in seconds. Wait that duration before retrying.

Handling Errors in Code

const res = await fetch('https://api.kakunin.ai/v1/agents', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${apiKey}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ name: 'my-agent', model: 'gpt-4o', version: '1.0' }),
});

if (!res.ok) {
  const { error } = await res.json();
  // Use res.status for branching, error string for logging
  if (res.status === 429) {
    const retryAfter = res.headers.get('Retry-After');
    throw new Error(`Rate limited — retry after ${retryAfter}s`);
  }
  throw new Error(`Kakunin API error ${res.status}: ${error}`);
}

On this page