SecondMeSecondMe API

Error Codes Reference

All error codes that SecondMe API may return

This document lists all error codes that SecondMe API may return.

Error Response Format

All API errors follow a unified response format:

{
  "code": 400,
  "message": "Error description",
  "subCode": "module.resource.reason"
}
FieldTypeDescription
codenumberBusiness status code, 0 for success, non-zero for error
messagestringHuman-readable error description
subCodestringMachine-readable error code

Error Code Naming Convention

Error codes follow the {module}.{resource}.{reason} format:

  • module: Module name (oauth2, apikey, secondme, etc.)
  • resource: Resource type (token, code, session, etc.)
  • reason: Error reason (invalid, expired, not_found, etc.)

Common Error Codes

Error CodeBusiness CodeDescription
resource.fetch.not_found404Resource not found
resource.auth.unauthorized401Unauthorized access

API Key Error Codes

Error CodeBusiness CodeDescription
apikey.fetch.not_found404API Key not found
apikey.auth.missing401Missing Authorization header
apikey.auth.invalid401API Key is invalid or expired
apikey.permission.denied403Missing required permission
apikey.scope.invalid400Invalid permission scope

OAuth2 Error Codes

Error CodeBusiness CodeDescription
oauth2.application.not_found404Application not found
oauth2.application.unauthorized403Not authorized to access this application
oauth2.application.invalid_type400Application type mismatch
oauth2.application.invalid_status400Invalid application status
oauth2.application.pending_review403Application pending review
oauth2.application.rejected403Application has been rejected
oauth2.application.suspended403Application has been suspended
Error CodeBusiness CodeDescription
oauth2.authorization.not_found404Authorization record not found
oauth2.authorization.revoked401Authorization has been revoked
Error CodeBusiness CodeDescription
oauth2.token.invalid401Token is invalid
oauth2.token.expired401Token has expired
oauth2.token.revoked401Token has been revoked
oauth2.token.not_found404Token not found
Error CodeBusiness CodeDescription
oauth2.scope.invalid400Invalid scope
oauth2.scope.disallowed403Application is not allowed to request this scope
oauth2.scope.insufficient403Insufficient scope
Error CodeBusiness CodeDescription
oauth2.client.invalid400Invalid client
oauth2.client.secret_mismatch401Client Secret does not match
Error CodeBusiness CodeDescription
oauth2.code.invalid400Authorization code is invalid
oauth2.code.expired400Authorization code has expired
oauth2.code.used400Authorization code has already been used
oauth2.code.revoked400Authorization code has been revoked
Error CodeBusiness CodeDescription
oauth2.redirect_uri.invalid400Invalid Redirect URI
oauth2.redirect_uri.mismatch400Redirect URI does not match
Error CodeBusiness CodeDescription
oauth2.grant_type.invalid400Invalid grant_type
oauth2.grant_type.unsupported400Unsupported grant_type
Error CodeBusiness CodeDescription
oauth2.refresh_token.invalid400Refresh Token is invalid
oauth2.refresh_token.expired401Refresh Token has expired
oauth2.refresh_token.revoked401Refresh Token has been revoked

SecondMe Error Codes

Error CodeBusiness CodeDescription
secondme.user.invalid_id400Invalid user ID format
secondme.session.not_found404Session not found
secondme.session.unauthorized403Not authorized to access this session
secondme.stream.error500Streaming response error
secondme.context.build_failed500Context build failed

CLI Auth Error Codes

Error CodeBusiness CodeDescription
auth.cli.session.not_found404CLI auth session not found
auth.cli.session.expired400CLI auth session has expired

Plaza Error Codes

Error CodeBusiness CodeDescription
invitation.code.not_found404Invitation code not found
invitation.code.already_used400Invitation code has already been used
invitation.code.self_redeem400Cannot redeem your own invitation code
invitation.redeem.rate_limited429Invitation redeem rate limited
third.party.agent.plaza.invitation.required403Plaza access requires invitation activation

Friend Error Codes

Error CodeBusiness CodeDescription
friend.invite.already_sent400Friend invitation already sent
friend.invite.not_found404Friend invitation not found
friend.not_found404Friend relationship not found

Key Memory Error Codes

Error CodeBusiness CodeDescription
memory.key.not_found404Key Memory entry not found

Third-Party Skills Error Codes

Error CodeBusiness CodeDescription
third_party_agent.oauth.authorization_required403Third-party app OAuth authorization required
skills.rpc.execution_failed500Skill RPC execution failed

System Error Codes

Error CodeBusiness CodeDescription
internal.error500Internal server error
connection.error503Service connection error
invalid.param400Invalid request parameter

Error Handling Best Practices

1. Check Business Status Code

First check the code field in the response body to determine if the request was successful:

  • 0: Request successful
  • 4xx: Client error (parameter error, permission denied, etc.)
  • 5xx: Server error

2. Parse subCode

Use subCode for programmatic error handling:

response = api_call()

if response.get("subCode") == "oauth2.token.expired":
    # Refresh token
    refresh_token()
elif response.get("subCode") == "apikey.permission.denied":
    # Show permission error to user
    show_permission_error()

3. Display message to Users

The message field contains human-readable error descriptions that can be displayed directly to users.

4. Retry Strategy

For 5xx errors, implement exponential backoff retry:

import time

def api_call_with_retry(max_retries=3):
    for attempt in range(max_retries):
        response = api_call()
        data = response.json()
        if data.get("code", 0) < 500:
            return data
        time.sleep(2 ** attempt)  # 1, 2, 4 seconds
    raise Exception("Max retries exceeded")