Skip to main content
Last updated on
Advanced — 0.0.x primitives

You don't need this page for a normal integration. Use the quickstarts and createMythos() instead. These low-level functions remain exported for custom setups.

Errors (Node.js)

Typed errors thrown by @mythos-work/sdk.

MythosError​

Base class for SDK errors.

typescript
class MythosError extends Error {
readonly code: string;
}

InsufficientFundsError​

typescript
class InsufficientFundsError extends MythosError
PropertyValue
codeINSUFFICIENT_FUNDS
messageInsufficient funds in wallet

Thrown by reportUsage when Mythos returns 402.

SessionNotFoundError​

typescript
class SessionNotFoundError extends MythosError
PropertyValue
codeSESSION_NOT_FOUND
messageSession not found: {jti}

Thrown by reportUsage when Mythos returns 404.

MythosConfigError​

typescript
class MythosConfigError extends MythosError
PropertyValue
codeCONFIG_ERROR

Thrown by verifyLaunchToken when no listing ID is configured — MYTHOS_LISTING_ID / MYTHOS_LISTING_IDS is unset and resolveListingIds (if provided) resolved no IDs. If you use the requireLaunchToken middleware instead of calling verifyLaunchToken directly, this is caught internally and mapped to a 500 response.

InvalidLaunchTokenError​

typescript
class InvalidLaunchTokenError extends MythosError
PropertyValue
codeINVALID_LAUNCH_TOKEN
messageInvalid launch token (default)

Thrown by verifyLaunchToken for a structurally invalid token — missing required claims, missing/invalid aud, or a listingId claim that doesn't match a configured listing ID. If you use the requireLaunchToken middleware instead of calling verifyLaunchToken directly, this is caught internally (alongside JOSE verification errors) and mapped to a 401 response.

ProducerMismatchError (0.5.0)​

Extends InvalidLaunchTokenError, with code PRODUCER_MISMATCH, HTTP 401 and message This app is bound to a different Mythos Producer. Check MYTHOS_KEY. Raised when a configured key does not match the launch, handshake or callback pkh. Legacy middleware keeps its invalid-token 401; handshake and callback return {"error":"Producer mismatch"}, without invoking the registration callback. See exact response bodies.

InvalidUsageError​

typescript
class InvalidUsageError extends MythosError
PropertyValue
codeINVALID_USAGE

Thrown by reportUsage when credits isn't a positive integer — a caller bug, not an API failure.

HTTP mapping in route handlers​

typescript
import { MythosError, InsufficientFundsError, SessionNotFoundError } from '@mythos-work/sdk';

try {
await reportUsage(sessionJti, { credits: 1 });
} catch (err) {
if (err instanceof InsufficientFundsError) {
res.status(402).json({ error: err.message, code: err.code });
} else if (err instanceof SessionNotFoundError) {
res.status(404).json({ error: err.message, code: err.code });
} else if (err instanceof MythosError) {
res.status(402).json({ error: err.message, code: err.code });
} else {
res.status(503).json({ error: 'Failed to report usage' });
}
}

See also​