Skip to content

10. Plan Management (Plan) ​

10.1 List All Plans ​

Endpoint: GET /api/plan/

Auth: Admin

Query parameters:

ParameterTypeDescription
pintPage number, default 0

Response:

json
{
  "success": true,
  "message": "",
  "data": [
    {
      "id": 1,
      "name": "Basic Plan",
      "price": 99.00,
      "tokens": 500000000,
      "model_limits": "{\"gpt-4o\":{\"request_month\":1000,\"token_month\":50000000}}",
      "default_model": "gpt-4o",
      "description": "Basic plan description",
"features": ["1000 API calls/month", "GPT-4o support"],
      "sort": 0,
      "status": 1,
      "duration_days": 30,
      "duration_text": "30 days",
      "recommended": false,
      "created_time": 1718000000
    }
  ]
}

Response fields:

FieldTypeDescription
iduintPlan ID
namestringPlan name
pricefloat64Price
tokensint64Token quota
model_limitsstringModel limit config as JSON; key is the model name, value is a ModelLimitRule
default_modelstringDefault model name. Requests for models not in model_limits are forwarded here for billing; empty means no forwarding and unconfigured models yield 422
descriptionstringDescription
featuresarray<string>Feature list, one item per line on the user-facing plan card
sortintSort weight
statusintStatus: 1=listed, 0=unlisted
duration_daysintValidity in days
duration_textstringValidity display text
recommendedboolWhether the plan is recommended

10.2 Search Plans ​

Endpoint: GET /api/plan/search

Auth: Admin

Query parameters:

ParameterTypeDescription
keywordstringSearch keyword

10.3 Get Plan Detail ​

Endpoint: GET /api/plan/:id

Auth: Admin

10.4 Create a Plan ​

Endpoint: POST /api/plan/

Auth: Root

Request body:

json
{
  "name": "Basic Plan",
  "price": 99.00,
  "tokens": 500000000,
  "model_limits": "{\"gpt-4o\":{\"request_month\":1000,\"token_month\":50000000}}",
  "default_model": "gpt-4o",
  "description": "Basic plan description",
  "features": "Feature description",
  "sort": 0,
  "status": 1,
  "duration_days": 30,
  "duration_text": "30 days",
  "recommended": false
}

10.5 Update a Plan ​

Endpoint: PUT /api/plan/

Auth: Root

Same shape as create; must include the id field.

model_limits field format:

Keys are model names; values are ModelLimitRule objects:

json
{
  "gpt-4o": {
    "period_h": 5,
    "request_period": 100,
    "request_week": 500,
    "request_month": 2000,
    "token_period": 500000,
    "token_week": 2000000,
    "token_month": 10000000
  }
}
FieldTypeDescription
period_hintRolling window length in hours, default 5
request_periodint64Max requests per rolling window
request_weekint64Max requests per week
request_monthint64Max requests per month
token_periodint64Max tokens per rolling window
token_weekint64Max tokens per week
token_monthint64Max tokens per month

default_model field notes:

  • When a user requests a model that is not in model_limits, the system forwards the request to the model named in default_model.
  • default_model must be a model already configured in model_limits; otherwise creating/updating the plan returns an error.
  • If default_model is empty and the requested model is not in model_limits, the response is 422.
  • After forwarding, the actual upstream request uses default_model; the model name recorded in logs is also default_model.

10.6 Delete a Plan ​

Endpoint: DELETE /api/plan/:id

Auth: Root