import { IaGenifyError, NotEnoughCredits, Unauthorized } from "iagenify" ;
try {
await api.models.turn({ model, messages });
} catch (err) {
if (err instanceof NotEnoughCredits) { /* 402 , never retried */ }
else if (err instanceof IaGenifyError) console.error(err.status, err.code, err.message);
}from iagenify import IaGenifyError, NotEnoughCredits, Unauthorized
try :
api.models.turn(model=model, messages=messages)
except NotEnoughCredits:
pass # 402, never retried
except IaGenifyError as error:
print(error.status, error.code, error)Match on code, never on the message: codes are the contract, messages are written for a person and are translated, shortened and improved.
Credits Code Status Means not_enough_credits 402 The balance will not cover it. Thrown as NotEnoughCredits, and never retried. insufficient_credits 402 The same, for a cloud add-on purchase. The message names the price and the balance.
Creating and running an agent Code Status Means machine_required 400 No machine, or one that is not a computer, a phone or a cloud workspace. files_required 400 A phone or cloud workspace without the six file operations. The message names what is missing. model_required 400 No model, and no session to take one from. invalid_mode 400 A mode outside the four. unknown_tool 400 A tool name the engine does not know. invalid_context 400 contextTokens below 10 000, or not whole.invalid_shell 400 A shell with no run function. invalid_custom_tool 400 No description, no run, a reserved name, or a bad category. invalid_media 400 A media key that is not one of the four. invalid_agent 400 An agent name that is not in the library. invalid_session_id 400 Not a session identifier. workspace_not_allowed 400 A workspace other than the package's own folder. inputs_required 400 run() with neither a message nor inputs.context_too_large 400 The conversation will not fit. Refused before any debit.
Sessions and checkpoints Code Status Means session_required 400 The call needs memory: true. agent_running 409 It is answering. stop() first. checkpoints_disabled 400 checkpoints: false.invalid_checkpoint 400 Not a whole number of at least 1. checkpoint_not_found 404 No such message. The message lists what is available. checkpoint_compacted 404 That message was summarised away.
Model turns Code Status Means turn_failed 502 The provider refused the turn. Its message is carried, redacted. turn_incomplete 502 The stream ended without a result. stream_failed 502 The stream broke. Retried once.
Files, locally and on the account Code Status Means local_files_require_node 400 The runtime has no filesystem. storage_not_on_this_machine 409 That storage belongs to another computer. invalid_path 400 Absolute, outside the workspace, or the root. path_not_found 404 Nothing there. path_exists 409 The destination is taken. not_a_file · not_a_folder 400 The path is the other kind. missing_content · invalid_content 400 Nothing to write, or a type that cannot be written. file_not_found · file_missing_on_disk 404 No such file on the account, or the record without the bytes.
Storages Code Status Means storage_not_found 404 No such storage on this account. storage_not_local 400 Not a computer: use run(). storage_is_phone 400 Its files are in that phone's browser. storage_is_local 400 A computer keeps no bytes on the account. invalid_service 400 Not nosql, sql or object. cloud_storage_limit 403 The plan's count for that service is used. quota_exceeded 403 The write would pass a ceiling. query_timeout 408 A statement ran too long. invalid_key · object_not_found 400 · 404 An unusable key, or nothing at it. embedding_unavailable 503 Semantic search refuses rather than answering on a fallback.
Cloud add-ons Code Status Means invalid_addon 400 Not database or object. invalid_gb 400 Not a whole number of at least 1, or past the 100 GB limit.
Search, fetch, convert Code Status Means query_required · url_required 400 A required field is missing. url_refusee · invalid_url 400 The address is refused by the guard, or unusable. fetch_failed 502 The page could not be opened. The credit is given back. unsupported_conversion 400 The pair is not in the matrix. The message names the possible targets. missing_formats · missing_source 400 No formats, or no source. conversion_failed 502 The converter refused the bytes. The credit is given back.
MCP Code Status Means url_not_https · url_blocked 400 Plain http, or an address that is not public. mcp_token_malformed 400 The token contains a space. mcp_token_required · mcp_unauthorized 401 A token is wanted, or was refused. mcp_redirect 502 A redirect. They are never followed. mcp_protocol_unsupported 502 No revision in common. mcp_unreachable · mcp_timeout 502 · 504 No answer in time. mcp_error · mcp_http_error · mcp_bad_response 502 A protocol error, an HTTP refusal, or an unreadable answer.
Workflows Code Status Means invalid_workflow 400 The definition is refused. The message names the step and the problem. run_not_waiting 400 The run is not stopped at a human step. run_not_retryable 400 It is still going, or a step before the chosen one did not succeed. step_not_found · step_not_executable 400 No such step, or a human step has nothing to execute. timeout 408 wait() gave up. The run keeps going.
Domains and mail Code Status Means domain_taken 409 Already attached, on some account. domain_not_attached 409 We only write in a zone we hold. mail_would_replace_mx 409 Live mail is here. details.current says where it goes. mail_not_enabled 403 The host has no mail records yet. mail_not_in_plan 403 The plan has no mail service. address_taken · address_reserved 409 · 400 Taken as a mailbox or an alias, or a reserved name. dmarc_step_too_big 400 A jump straight to the strictest policy. dmarc_not_enforced · public_url_missing 400 The two gates a logo has to pass.
Hosting Code Status Means invalid_kind · invalid_slug 400 No such kind, or an unusable or reserved slug. slug_taken 409 Somebody has that address. hosting_limit · hosting_not_in_plan 403 The plan's count is used, or it has no hosting. hosting_kind_unavailable 501 That kind cannot serve. nothing_to_deploy 400 No files, no code, or a file with no path. deploy_too_large 413 Past a bound. The message names the file.
Skills and subagents Code Status Means invalid_name 400 Not lowercase letters, digits and dashes. not_found 404 In neither source. item_on_computer 409 It exists only on this computer. The message names the folder. not_a_skill 400 Only skills have files.
Errors The classes, and what to catch. → Retries What is tried again. → Credits The 402 family. →