Skip to content

Portal

The Manager API is a set of RESTful interfaces provided by the User Portal that enables programmatic access to account management features. While the User Portal serves as a web-based management console where users can view account balances and usage statistics, the Manager API extends these capabilities by allowing users to integrate account data querying into their own systems and workflows.

The Manager API addresses several key use cases for power users and enterprise customers:

  • Automated Monitoring: Integrate balance and usage statistics into internal monitoring systems for real-time alerts and dashboards
  • Data Analysis: Export usage data in bulk for analysis, reporting, and business intelligence
  • Cost Management: Track token consumption programmatically to optimize spending and set budget controls
  • System Integration: Connect account data with existing enterprise resource planning (ERP) or billing systems
Use CaseDescription
Real-time Balance MonitoringMonitor account balance thresholds and trigger alerts when balance runs low
Usage AnalyticsCollect and analyze token consumption patterns across different models and time periods
Cost AllocationTrack usage by token or organization for internal cost allocation and chargeback
Automated ReportingGenerate periodic usage reports for stakeholders and finance teams
Budget ControlImplement spending limits and automated notifications based on usage thresholds
StatusDescription
ActiveThe API key is valid and can be used for authentication
DisabledThe API key is temporarily disabled and cannot be used
RevokedThe API key has been permanently revoked and cannot be restored
  1. Log in to your Yuansuan Portal account
  2. Go to Settings or Account Management
  3. Click on the Management API Keys tab
  1. Click the Create API Key button
  2. Fill in the required information:
FieldDescriptionRequirements
NameA descriptive name for the API key1-100 characters, required
DescriptionPurpose or usage contextMax 500 characters, optional
ExpirationWhen the key should expireUnix timestamp or select “Never expires”
ScopesPermission levelsSelect required permissions, optional

Choose one of the following:

  • Never expires: The key remains valid indefinitely
  • Custom date: Select a specific expiration date
  • Time period: Set expiration (e.g., 30 days, 90 days, 1 year)

After clicking Create:

  1. A modal will appear displaying your complete API key starting with sk_mg_
  2. Copy the API key immediately - click the copy button or use Ctrl/Cmd + C
  3. Store it securely in:
    • Environment variables
    • A password manager
    • A secure secrets management system
  4. Click I have saved my API key to close the modal

Warning: You cannot retrieve the complete API key again after closing this window.

  1. Navigate to Settings > API Keys > Management API Keys
  2. View all your API keys in a table format

Each API key shows:

ColumnDescription
NameThe name you gave the API key
Display KeyMasked version (e.g., sk_mg_a1b2...5678)
StatusCurrent status (Active/Disabled/Revoked)
Last UsedTimestamp of last usage
ExpiresExpiration date or “Never”
CreatedCreation date
  • Use the Status filter to show only Active, Disabled, or Revoked keys
  • Use the Search box to find keys by name
  • Navigate through pages using the pagination controls
  1. Find the API key you want to update in the list
  2. Click the Edit button (pencil icon) in the actions column

You can update:

  • Name: Change the display name
  • Description: Update the purpose or usage notes

Note: You cannot change the API key value itself. To get a new key, create a new one and delete the old one.

  1. Click Save to apply changes
  2. A success message will confirm the update
  1. Find the API key you want to delete
  2. Click the Delete button (trash icon)
  1. Read the warning message carefully
  2. Confirm by entering the API key name
  3. Click Confirm Delete

Warning: This action cannot be undone. The API key will immediately stop working.

  1. Find the API key you want to revoke
  2. Click the Revoke button
  1. Review the revocation details
  2. Click Confirm Revoke

The API key status will change to Revoked and it can no longer be used.

  1. Use the status filter to show Revoked keys
  2. Locate the key you want to restore
  1. Click the Restore button
  2. Confirm the restoration action

The API key status will change back to Active.

https://portal-api.r9s.ai/api/v1/portal/management

All Manager API endpoints require Bearer Token authentication using a Management API Key.

Authorization: Bearer sk_mg_xxxxxxxxxxxxxxxxxx

Management API Keys can be generated through the User Portal under Settings > API Keys. Each key has specific permissions and can be revoked at any time.

EndpointMethodDescription
/balanceGETRetrieve current account balance information
/usageGETQuery token usage records within a specified time range

To ensure service stability and prevent abuse, the Manager API implements rate limiting:

Limit TypeValue
Rate Limit2 requests per second
Concurrency Limit20 concurrent requests
  • Implement exponential backoff retry logic
  • Batch requests when possible to reduce API calls
  • Cache frequently accessed data locally
  • Use webhooks or polling intervals appropriate to your needs
HTTP StatusError CodeDescription
400invalid_requestInvalid request parameters
401unauthorizedAuthentication failed or missing
429rate_limit_exceededRate limit exceeded
500internal_errorServer-side error
{
"meta": {
"code": 401,
"message": "unauthorized: invalid api key",
"request_id": "abc123"
},
"data": null
}