Machine-readable codes. Values match C aimux_error_code_t / Go Code.
16 variant codes: 1–17 (1 is the catch-all; 4 is retired). A code outside
that set is a header/library mismatch and fails with StateError, not an
error type. Every HTTP-shaped failure
arrives as apiCall, classified
by AimuxException.status (401 auth, 404 model, 429 rate limit;
-1 = no HTTP response was ever observed — a missing API key, an error
built without a request, or a transport failure).
aimux_free_string — frees aimux-allocated result strings. Lazily
initialized so pure-Dart tests that never produce a native string do not
dlopen the library.
Validate a caller-supplied raw JSON string before it crosses the C
C ABI; throws FormatException naming param (source) on bad
syntax. Null passes through (optional parameters); empty/blank is rejected
like the FFI does for REQUIRED params, unless emptyIsDefault — pass it for
every OPTIONAL JSON param (nullable in the Dart signature: config_json of
provider/router/moa, opts_json of embed / file upload / transcription),
where the FFI treats NULL/empty as "use defaults".
Reject a JSON value that jsonDecode/jsonEncode accept but serde_json
on the Rust side does not. Divergences (all three verified against
serde_json 1.0.151):
jsonEncode for a caller-supplied value the binding serializes itself
(prompts, call options, ProviderConfig) — pre-validated with the same
rule checkJson applies to caller-supplied JSON text, because nothing
downstream would check it.
Decode the aimux_error_t *e returned by a call that can fail in
AiMuxError ([AiMuxError] in aimux-ffi.h). NULL → returns (success).
Codes 1..17 become AimuxException; 200..206 become StateError.
The returned error is always freed.
toNativeUtf8 with the two checks a C string needs and a Dart String
does not enforce, applied to every string parameter that crosses the ABI
(model ids, api keys, base URLs, dir paths, base64 payloads, media types,
JSON text):
Provider API call failed (AI SDK APICallError analogue) — every
HTTP-shaped failure. status is the classification (401 auth, 404 model,
429 rate limit + retryMs); -1 means no HTTP response was ever observed
— a missing API key, an error built without a request, or a transport
failure. Read retryable to decide on a retry; status cannot tell those
two apart.
Recording failure reported by initRecording() / recordingTryFlush().
NOT an AimuxException — the recorder is a separate subsystem with its
own closed error set.
Retrying stopped (AIMUX_E_RETRY): reason says why, message carries
the composed summary ("Failed after N attempts…"), and errors keeps the
per-attempt history, oldest first — each entry is itself a fully decoded
AimuxException (an APICallError keeps its whole detail set; a nested
RetryError recurses).