Client SDK · Reference

Exports.

Every class, dataclass, and type the matilda-client package exports.

Client

ExportKindDescription
MatildaClientclassMain client class — owns the chat, files, conversations, feedback, api_keys, and auth resources.
MatildaConfigdataclassClient configuration (frozen).
TokenProvidertype aliasCallable[[bool], Awaitable[str | None]] — async token provider.

Chat responses and events

ExportKindDescription
MatildaChatResponsedataclassCollected response from chat.create().
MatildaObjectResponse[T]dataclasschat.create_object() response (extends MatildaChatResponse, adds object).
ChatEventtype aliasUnion of the 14 stream event dataclasses.
MatildaObjectEvent[T]type aliaschat.stream_object() events — all chat events, plus a final ObjectEvent.
ObjectEvent[T]dataclassTerminal structured-output event (type="object").
ResponseCreateddataclassresponse.created — stream ID.
OutputTextDeltadataclassresponse.output_text.delta — text chunk.
OutputTextReplacedataclassresponse.output_text.replace — safety replacement.
StatusEventdataclassresponse.status — lifecycle status.
QueuedEventdataclassresponse.queued — queue position.
ToolCallStarteddataclassresponse.tool_call.started.
ToolCallProgressdataclassresponse.tool_call.progress.
ToolCallCompleteddataclassresponse.tool_call.completed.
GenerationStatusdataclassresponse.generation_status.
UsageEventdataclassresponse.usage — wraps Usage.
UsagedataclassToken usage payload.
CursorEventdataclassresponse.cursor — durable cursor.
Truncateddataclassresponse.truncated.
Completeddataclassresponse.completed.
ResponseErrordataclassresponse.error — code + message.
StreamErrorInfodataclassError entry in MatildaChatResponse.errors.
EventCallbacktype aliasCallable[[ChatEvent], None].
ChatErrorCodetype aliasLiteral union of the chat error codes.

Errors

ExportKindDescription
MatildaErrorclassBase class for every SDK error.
MatildaAPIErrorclassHTTP error (status, response_text).
QuotaExceededErrorclass429 quota error with structured quota attributes.
MatildaStreamErrorclassTerminal stream error event (code).
SafetyReplaceErrorclassSafety filter replacement (categories).
MatildaObjectParseErrorclassStructured output parse/validation failure (raw, cause).
UploadErrorclassFile upload failure.
AuthErrorclassOAuth error (code, retryable).

Auth

ExportKindDescription
AuthResourceclassManaged auth on client.authlogin_with_browser, login_with_device_flow, refresh_token, get_tokens, logout.
TokenManagerclassPer-session token manager with single-flight refresh.
create_token_managerfunctionTokenManager factory.
TokenSetdataclassOAuth token set (access_token, refresh_token, id_token, expires_at).
StorageAdapterprotocolPluggable token storage (sync or async).
MemoryStorage / memory_storageclass / functionIn-memory StorageAdapter.
FileTokenStore / create_file_token_storeclass / function0600 JSON file store with .store and cross-process .lock.
LoopbackReceiver / create_loopback_receiverclass / functionRFC 8252 loopback redirect receiver.
run_loopback_login_flowfunctionHeadless PKCE loopback login.
run_device_login_flowfunctionHeadless RFC 8628 device login.
default_device_on_eventfunctionPrints the device user code to stderr.
LoginFlowEventtype aliasStateEvent | AuthorizeUrlEvent | UserCodeEvent.
StateEvent / AuthorizeUrlEvent / UserCodeEventdataclassesLogin flow state events.
AuthServerMetadatadataclassRFC 8414 server metadata.
fetch_auth_server_metadatafunctionMetadata discovery.
DeviceAuthorizationdataclassDevice-flow code + URIs.
request_device_code / poll_device_tokenfunctionsDevice-flow grant halves.
BeginLoginResult / begin_login / complete_logindataclass / functionsStateless redirect-login halves.
exchange_code_for_tokensfunctionAuthorization-code exchange.
refresh_token_grantfunctionRaw refresh-token grant.
create_pkce_pairfunctionPKCE verifier + S256 challenge.
build_authorize_urlfunctionConstruct the authorize URL.
assert_statefunctionValidate the OAuth state round-trip.
random_statefunctionHigh-entropy state value.
base64_url_encodefunctionPadding-free base64url.

Files and feedback types

ExportKindDescription
FileCompletedataclassUpload completion result (file_id, status).
FeedbackPlatformtype alias'web' | 'ios' | 'android' | 'unknown'.
ReportReasontype alias'harmful' | 'inaccurate' | 'off_topic' | 'privacy' | 'other'.

Constants and version helpers

ExportValueDescription
DEFAULT_BASE_URLhttps://matilda.maincode.com/apiProduction API base URL.
DEFAULT_CHUNK_SIZE8 MiBChunked-upload part size.
DEFAULT_CHUNKED_THRESHOLD16 MiBChunked-upload file-size threshold.
DEFAULT_PART_CONCURRENCY4Parallel upload parts.
DEFAULT_MAX_PART_RETRIES3Retries per upload part.
MAX_FILE_COUNT5Maximum files per request.
S3_MIN_CHUNK_SIZE5 MiBS3 multipart minimum.
DEFAULT_STALL_TIMEOUT_MS45 000SSE stall watchdog default.
DEFAULT_SUCCESS_REDIRECThttps://matilda.maincode.com/cli/signed-inBrowser-login success redirect.
MATILDA_API_VERSION_HEADERX-Matilda-API-VersionAPI version header name.
MATILDA_CURRENT_API_VERSIONCurrent API version string.
CHAT_ERROR_CODESfrozensetThe chat error codes.
sdk_version()Installed package version.