Common errors
The ulex errors you will actually hit, each with its cause, a diagnosis command, and a fix. Grouped by where you hit them, with the three that account for most failures at the top.
Three errors account for most failed agent runs. Learn them and the rest is a lookup.
| Error | Why it happens | Fix |
|---|---|---|
403 connection_not_active | you created a connection and tried to log in without activating it | POST /connections/{id}/activate |
400 invalid_grant | you exchanged an authorization code twice, or your redirect_uri does not match | log in again; do not retry |
401 invalid_token | the token's iss does not match the environment you are calling | check the issuer |
Everything else is below, grouped by where you hit it.
#Decode anything
{ "name": "ulex_explain_error", "arguments": { "code": "domain_not_verified" } }{
"code": "domain_not_verified",
"type": "invalid_request_error",
"http_status": 412,
"retryable": false,
"message": "The domain acme.example has not been verified for this organization.",
"causes": [
"ulex_verify_domain was never called for this domain.",
"The DNS TXT record at _ulex-challenge.acme.example is missing or has not propagated.",
"The domain is verified for a different organization than the one on the connection."
],
"fixes": [
"Call ulex_verify_domain with the organization_id and domain_id.",
"Publish the DNS TXT record and wait for propagation (in local in-memory mode or on a non-HIPAA tenant with allow_mocks: true, verification resolves immediately)."
],
"docs_url": "https://docs.ulexid.com/api-reference/organizations#domain-verification"
}#Authentication and tokens
#401 unauthenticated
No Authorization header. Add Authorization: Bearer ulex_sk_live_…. Note the case: bearer lowercase is accepted by the spec and rejected by ulex, deliberately, so a copy-paste that lost the capital fails loudly rather than silently.
#401 invalid_api_key
The value is malformed. In practice it is a truncated paste or a trailing newline. printf '%s' "$ULEX_API_KEY" | wc -c should be 45.
#401 api_key_expired / api_key_revoked
curl -sS "$BASE/tenants/current/api-keys" -H "$ADMIN" | jq '.data[] | {id, name, prefix, expires_at, revoked_at, last_used_at}'Neither is retryable. Mint a new key and deploy it. If it was revoked and you did not revoke it, treat it as a compromise and go to Incident response.
#401 invalid_token
The token is not a JWT, or the iss is wrong, or the signature does not verify. A common cause is mixing a local in-memory token (http://127.0.0.1:3001) with a hosted token (https://ulexid.com), or sending a token issued for another tenant.
echo "$TOKEN" | cut -d. -f2 | base64 -d | jq '{iss, aud, exp, org_id}'iss must match your control plane issuer (https://ulexid.com, or http://127.0.0.1:3001 in local in-memory mode). There is no header that overrides it.
#401 token_expired
exp is in the past. Refresh. If you have no refresh token, the user logs in again. Do not retry the same access token.
#401 token_revoked
Revoked explicitly, or a refresh-token family was killed by reuse detection. The family is dead. Start a new login.
curl -sS -G "$BASE/audit-events" -H "$ADMIN" --data-urlencode 'action=authentication.session_revoked' \
--data-urlencode 'limit=10' | jq '.data[] | {timestamp, metadata, actor_type}'#403 insufficient_scope
The hint names the exact scope.
curl -sS -X POST "$BASE/tenants/current/api-keys" -H "$ADMIN" -H "$JSON" \
-d '{"name":"agent-v2","scope":["mcp:tools","read:organizations","write:organizations","read:users","write:users"],"expires_in_days":90}'Not retryable. A broader credential is required.
#403 cross_tenant
The resource belongs to another tenant. Check which credential you used. If you have two keys and one is stale, this is the symptom.
#400 invalid_grant
Three causes, and none of them is retryable:
| Cause | Tell |
|---|---|
| the authorization code was already exchanged | you have two calls doing the exchange, or a retry loop |
| the code expired | codes live 60 seconds |
the redirect_uri does not match the one in the authorization request | the error description says so |
Re-login, do not retry. A retry of an exchanged code can never succeed, and a retry of a refresh token kills the family.
{
"error": "invalid_grant",
"error_description": "The authorization code has already been used.",
"type": "authentication_error",
"code": "invalid_grant",
"request_id": "req_01M3PSW9R0175NAW62NYR403R8",
"retryable": false,
"hint": "Authorization codes are single use. Start a new login with ulex_simulate_login."
}#400 code_verifier_mismatch
PKCE. Either the verifier is for a different challenge, or you are not base64url-ing the SHA-256.
code_challenge = BASE64URL(SHA256(ASCII(code_verifier)))The RFC 7636 test vector, which the simulator honours for mock_sso:
verifier dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk
challenge E9MelhoQ2YvW96fl8sW7aTtZbGd0mY6Xl0e8Q1sCk#401 mfa_required
{
"error": {
"type": "authentication_error",
"code": "mfa_required",
"message": "A second factor is required before this authorization can complete.",
"retryable": false,
"hint": "Present the challenge to the user, or satisfy it with ulex_simulate_mfa { mode: 'satisfy' }."
}
}Not retryable on its own. Satisfy the challenge, then log in again. Retrying without satisfying it produces a second mfa_required.
#Connections and login
#403 connection_not_active
The single most common ulex error. New connections are draft and every login on a draft connection is refused.
curl -sS "$BASE/connections/$CON_ID" -H "$AUTH" | jq -r .state
curl -sS -X POST "$BASE/connections/$CON_ID/activate" -H "$AUTH" | jq -r .stateActivation is rejected with 409 invalid_state_transition when a domain is unverified, a SAML certificate has expired, or the organization is sso_only with no domains. POST /connections/{id}/verify tells you which.
#400 access_denied
| Sub-case | Cause | Fix |
|---|---|---|
sso_only org, wrong connection | you authenticated against a different connection | use organization.connection_id |
allowed_domains mismatch | the email's domain is not on the connection | add it, or use a corporate address |
allow_profiles_outside_organization: false | the domain is not a verified org domain | verify the domain |
user status is not active | suspended, inactive, or pending | unsuspend, or check the directory |
curl -sS "$BASE/users/$USER_ID" -H "$AUTH" | jq '{email, status, email_verified, directory_id}'#400 user_not_found on a mock login
The email is not in config.mock.seed_users.
curl -sS "$BASE/connections/$CON_ID" -H "$AUTH" | jq '.config.mock.seed_users[].email'For OIDC, set the legacy require_jit_provisioning field to false to allow an unknown user to be created at sign-in. true disables JIT creation. mock_sso does not do JIT; it matches the seed.
#412 domain_not_verified
curl -sS -X POST "$BASE/organizations/$ORG_ID/domains/$DOM_ID/verify" -H "$AUTH" | jq -r .stateIn prod with dns strategy, the TXT record must exist:
dig +short TXT _ulex-challenge.acme.example#Validation
#400 unknown_parameter
You sent a field the schema does not have. Requests are strict on purpose, so a typo surfaces instead of being silently ignored. environment is the usual culprit — it is never a parameter.
{
"error": {
"type": "invalid_request_error",
"code": "unknown_parameter",
"message": "Unrecognized parameter: environment",
"param": "environment",
"retryable": false,
"hint": "ulex derives the environment from the credential."
}
}#400 validation_failed
details maps field paths to messages.
{
"error": {
"type": "invalid_request_error",
"code": "validation_failed",
"message": "Request validation failed.",
"details": {
"slug": "Must be a lowercase URL slug",
"redirect_uris[0]": "Must be an https:// URL (http:// permitted only for loopback)"
}
}
}#400 invalid_json
jq . <<<"$BODY" >/dev/null || echo "not valid JSON"Common causes: a smart quote pasted from a document, a trailing comma, a ${VAR} that was never substituted inside single quotes, or a multi-line string in a shell heredoc.
#Conflicts
#409 resource_exists
A slug, email, or userName collision.
{
"error": {
"type": "conflict_error",
"code": "resource_exists",
"message": "A organization with that slug already exists.",
"param": "slug",
"details": { "slug": "already taken" }
}
}On POST /users this is not a failure to retry — it means the person already exists in the tenant, which is what you wanted. Reuse the id:
curl -sS -G "$BASE/users" -H "$AUTH" --data-urlencode "email=$EMAIL" | jq -r '.data[0].id'On a create, send an Idempotency-Key and the 409 becomes a clean replay of the original response.
#409 invalid_state_transition
cancelled a succeeded deployment
rolled back a failed deployment
activated a connection with an unverified domain
changed a SAML certificate and then tried to log in before re-activatingRead state before you act.
#409 resource_deleted
Soft-deleted and inside the 30-day restore window. Not readable, not writable, but the audit event exists.
#400 immutable_field
id, slug, object, created_at cannot change. organization.slug and application.slug are immutable for the life of the resource. connection.config.strategy can change, but it forces re-verification.
#413 scim_bulk_exceeded
Over 100 operations in one /scim/v2/Bulk request. Chunk at 100.
#Rate limits
#429 too_many_requests
The in-app shield uses per-IP token buckets: 600 sustained requests/minute (1,200 burst) on general routes and 60/minute (120 burst) on authentication/token routes. Buckets are per Lambda container; API Gateway is the distributed backstop. Pricing is usage-based and tenant resource counts do not impose plan limits.
{ "error": { "type": "rate_limited", "code": "too_many_requests", "message": "Rate limit exceeded. Back off and retry." } }Honor the Retry-After header and batch large operations. Rate limits has details.
#MCP
#401 mcp_unauthorized
No Authorization header, or the key lacks mcp:tools.
curl -sS -D- -X POST "https://ulexid.com/api/v1/mcp" \
-H "Authorization: Bearer $ULEX_API_KEY" \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-H "MCP-Protocol-Version: 2025-06-18" \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"probe","version":"1"}}}'The WWW-Authenticate header on a 401 points at the RFC 9728 metadata for the OAuth 2.1 flow.
#404 mcp_tool_not_found
{ "name": "ulex_list_tools", "arguments": { "include_schemas": true, "filter": "connection" } }Match the tool name exactly, including the ulex_ prefix. A JSON-RPC -32601 means the method name is wrong (tools/calll, not tools/call); a ulex mcp_tool_not_found inside result.isError means the tool name is wrong.
#Tool error versus protocol error
| Shape | Meaning |
|---|---|
result.isError: true with the ulex envelope in content[0].text | the tool ran and failed. Read error.retryable |
error: { code: -32601 } | the JSON-RPC method does not exist. A client bug |
error: { code: -32602 } | the JSON-RPC params are malformed. A client bug |
| HTTP 401/429 | authentication or a rate limit, before any tool ran |
Deeper: MCP issues.
#A diagnostic that answers most questions
BASE="https://ulexid.com/api/v1"
AUTH="Authorization: Bearer $ULEX_API_KEY"
RUN="diag-$(date +%H%M%S)"
curl -sS "$BASE/me" -H "$AUTH" | jq '{env: .tenant.environment, plan: .tenant.plan}'
curl -sS -G "$BASE/audit-events" -H "$AUTH" \
-H "X-Ulex-Correlation-Id: $RUN" \
--data-urlencode "correlation_id=$RUN" --data-urlencode 'order=desc' | jq -r '.data[] | "\(.timestamp) \(.action) \(.outcome) \(.error_code // "-") \(.request_id)"'
curl -sS -G "$BASE/connections/$CON_ID/auth-attempts?limit=5" -H "$AUTH" \
| jq '.data[] | {outcome, stage, error_code, error_message}'Run it with the same X-Ulex-Correlation-Id your failing run used, and every step lines up in one place.