Credit
Credit 分類提供組織 Credit 的查詢與額度分配:餘額、即將到期額度、入帳紀錄、消耗明細與總計、用量統計、計價規則與計價項目,以及成員、角色、對話平台三種額度的設定(列出、設定、更新、停用、是否需要額度),和依角色批次分配或停用成員額度。
前置說明
認證與路徑參數
除「計價規則」與「計價項目」外,所有 API 都要在 HTTP Header 帶 API Key:
Authorization: Api-Key {API_KEY}系統會依 API Key 自動帶出所屬組織與成員身分,/api/v1/credit/ 開頭的 API 不需要另外傳組織識別。路徑中需要的 ID 可以這樣取得:
organizationPk:呼叫GET /api/v1/organizations/,取回應中組織的id。錢包的
id:呼叫GET /api/v1/organizations/{id}/,取回應中的creditWallet.id。
呼叫頻率上限
需要 API Key 的 API,呼叫頻率上限是每一把 API Key 各自設定的每分鐘次數,由組織管理者在「組織設定 → API 金鑰」的「每分鐘請求數(RPM)」設定;同一把金鑰呼叫平台上所有 API 的次數合併計算,沒有設定上限的金鑰不受此限制。超過上限的請求會被拒絕並回傳 HTTP 429,請等到下一分鐘再重試。
「計價規則」與「計價項目」不需要 API Key,呼叫上限另依來源 IP 計算,見各 API 的標註。
額度怎麼運作
成員、角色、對話平台各有一層額度,對應後台「Credits → 額度分配」的三個分頁,三層各自計算:
成員額度:單一成員自己的用量上限。
角色額度:角色內所有成員共用的上限,與成員各自的額度分開計算。成員同時屬於多個需要額度的角色時,用量會累計到每一個角色,任一個角色的額度用完就會擋下。
對話平台額度:該對話平台(Inbox)AI 回覆的用量上限。MaiGPT 的對話平台不能設定額度。
每一層的規則相同:
需要額度:成員、角色、對話平台各有一個「需要額度」設定(回應欄位
creditQuotaRequired)。關閉時不檢查、也不累計這一層,直接使用組織錢包;開啟時必須有生效中的額度才能使用,沒有生效中的額度就會被擋下(成員與角色是不能使用消耗 Credit 的功能,對話平台是暫停 AI 回覆)。設定額度會自動開啟「需要額度」。同一個對象同時只能有一筆生效中的額度,已有生效中的額度時再設定會回
400,要先停用舊的。停用額度不會關閉「需要額度」:停用後對象會被擋下,直到設定新額度或解除額度限制:角色與對話平台用各自的「設定是否需要額度」API 解除;成員請由管理者在後台「Credits → 額度分配」解除,或用 依角色批次停用額度 帶
removeQuotaRequirement: true一次解除整個角色的成員。停用不會刪除紀錄,停用的額度仍會出現在「列出額度設定」中,isActive為false。設定額度的請求內容:
quotaLimit(額度上限,必填)、validFrom(生效時間,必填,ISO 8601)、validUntil(到期時間,選填,須晚於validFrom,且不可晚於組織最晚一筆入帳額度的到期日)、resetPeriod(用量歸零週期:none、daily、weekly、monthly,預設none)、note(備註,選填)。路徑中的 ID:
memberPk取自 列出成員額度現況、groupPk取自 列出角色額度現況、inboxPk取自 列出對話平台額度現況 回應中的id;額度設定本身的id取自各自的「列出額度設定」。
權限與計費模式
每支 API 下方都標明所需權限與計費模式前提。API Key 以建立它的成員身分呼叫,權限依該成員所屬角色判斷。以下兩種情形會被拒絕並回傳 HTTP 403:
權限不足:金鑰所屬成員的角色沒有該 API 標明的權限(「Credit 管理權限」、「用量統計權限」或「組織概覽權限」)。請組織管理者到「組織設定 → 角色」為該成員的角色開啟對應權限。
組織不是 Credit 計費模式:標明「組織須為 Credit 計費模式」的 API,只開放給 Credit 計費模式的組織。可呼叫
GET /api/v1/organizations/{id}/確認:回應中organizationPlan.billingMode為credit(或組織尚未有方案、organizationPlan為空)即可使用這些 API;如需改用 Credit 計費模式,請聯繫 MaiAgent 窗口。
查詢 Credit 餘額
GET /api/v1/credit/wallets/
參數
page
❌
integer
A page number within the paginated result set.
pageSize
❌
integer
Number of results to return per page.
程式碼範例
回應內容
狀態碼: 200
回應結構範例
回應範例值
取得錢包詳情
GET /api/v1/credit/wallets/{id}/
參數
id
✅
string
A UUID string identifying this Credit Wallet.
程式碼範例
回應內容
狀態碼: 200
回應結構範例
回應範例值
取得錢包餘額
GET /api/v1/credit/wallets/{id}/balance/
參數
id
✅
string
A UUID string identifying this Credit Wallet.
程式碼範例
回應內容
狀態碼: 200
回應結構範例
回應範例值
查詢即將到期額度
GET /api/v1/credit/wallets/{id}/expiring-credits/
參數
id
✅
string
A UUID string identifying this Credit Wallet.
程式碼範例
回應內容
狀態碼: 200
回應結構範例
回應範例值
查詢入帳紀錄
GET /api/v1/credit/wallets/{id}/topup-history/
參數
id
✅
string
A UUID string identifying this Credit Wallet.
程式碼範例
回應內容
狀態碼: 200
回應結構範例
回應範例值
列出消耗明細
GET /api/v1/credit/transactions/
參數
page
❌
integer
A page number within the paginated result set.
pageSize
❌
integer
Number of results to return per page.
程式碼範例
回應內容
狀態碼: 200
回應結構範例
回應範例值
取得單筆消耗明細
GET /api/v1/credit/transactions/{id}/
參數
id
✅
string
A UUID string identifying this Credit Transaction.
程式碼範例
回應內容
狀態碼: 200
回應結構範例
回應範例值
查詢消耗紀錄
GET /api/v1/credit/transactions/history/
參數
category
❌
string
Credit item category (e.g. llm_token, platform_fee); agent_memory selects the AI memory lines, which llm_token then leaves out
endDate
❌
string
End date (inclusive, whole day in the platform timezone Asia/Taipei), format: YYYY-MM-DD
limit
❌
integer
Rows per page, capped at 100
page
❌
integer
1-based page number
search
❌
string
Case-insensitive match against transaction description and metadata
startDate
❌
string
Start date (inclusive, whole day in the platform timezone Asia/Taipei), format: YYYY-MM-DD
type
❌
string
Which rows to include: all ledger entries, consumption only, or credited only
程式碼範例
回應內容
狀態碼: 200
回應結構範例
回應範例值
查詢消耗總計
GET /api/v1/credit/transactions/history-summary/
參數
category
❌
string
Credit item category (e.g. llm_token, platform_fee); agent_memory selects the AI memory lines, which llm_token then leaves out
endDate
❌
string
End date (inclusive, whole day in the platform timezone Asia/Taipei), format: YYYY-MM-DD
search
❌
string
Case-insensitive match against transaction description and metadata
startDate
❌
string
Start date (inclusive, whole day in the platform timezone Asia/Taipei), format: YYYY-MM-DD
type
❌
string
Which rows to include: all ledger entries, consumption only, or credited only
程式碼範例
回應內容
狀態碼: 200
回應結構範例
回應範例值
查詢各分類 Credit 用量
GET /api/v1/organizations/{organizationPk}/usage-statistics/credit-categories/
參數
organizationPk
✅
string
A UUID string identifying this 組織 ID
endDate
❌
string
End date, format: YYYY-MM-DD
page
❌
integer
A page number within the paginated result set.
pageSize
❌
integer
Number of results to return per page.
startDate
✅
string
Start date, format: YYYY-MM-DD
timeGranularity
❌
string
Time granularity (hour/day/month)
程式碼範例
回應內容
狀態碼: 200
回應結構範例
回應範例值
查詢單一分類 Credit 用量
GET /api/v1/organizations/{organizationPk}/usage-statistics/credit-categories/{id}/
參數
id
✅
string
organizationPk
✅
string
A UUID string identifying this 組織 ID
endDate
❌
string
End date, format: YYYY-MM-DD
startDate
✅
string
Start date, format: YYYY-MM-DD
timeGranularity
❌
string
Time granularity (hour/day/month)
程式碼範例
回應內容
狀態碼: 200
回應結構範例
回應範例值
查詢計價項目的成員用量
GET /api/v1/organizations/{organizationPk}/usage-statistics/credit-categories/{itemPk}/members/
參數
itemPk
✅
string
organizationPk
✅
string
A UUID string identifying this 組織 ID
endDate
❌
string
End date, format: YYYY-MM-DD
page
❌
integer
A page number within the paginated result set.
pageSize
❌
integer
Number of results to return per page.
startDate
✅
string
Start date, format: YYYY-MM-DD
timeGranularity
❌
string
Time granularity (hour/day/month)
程式碼範例
回應內容
狀態碼: 200
回應結構範例
回應範例值
查詢單一成員的計價項目用量
GET /api/v1/organizations/{organizationPk}/usage-statistics/credit-categories/{itemPk}/members/{id}/
參數
id
✅
string
itemPk
✅
string
organizationPk
✅
string
A UUID string identifying this 組織 ID
endDate
❌
string
End date, format: YYYY-MM-DD
startDate
✅
string
Start date, format: YYYY-MM-DD
timeGranularity
❌
string
Time granularity (hour/day/month)
程式碼範例
回應內容
狀態碼: 200
回應結構範例
回應範例值
列出成員額度現況
GET /api/v1/organizations/{organizationPk}/credit-quota-members/
參數
organizationPk
✅
string
A UUID string identifying this 組織 ID
ordering
❌
string
Sort field (default '-created_at')
page
❌
integer
Page number
pageSize
❌
integer
Rows per page (max 100)
quotaStatus
❌
string
Filter by quota status
search
❌
string
Filter by member name, email, or member ID (case-insensitive substring)
程式碼範例
回應內容
狀態碼: 200
回應結構範例
回應範例值
列出角色額度現況
GET /api/v1/organizations/{organizationPk}/credit-quota-groups/
參數
organizationPk
✅
string
A UUID string identifying this 組織 ID
ordering
❌
string
Sort field (default '-created_at')
page
❌
integer
Page number
pageSize
❌
integer
Rows per page (max 100)
quotaStatus
❌
string
Filter by quota status
search
❌
string
Filter by group name or group ID (case-insensitive substring)
程式碼範例
回應內容
狀態碼: 200
回應結構範例
回應範例值
列出對話平台額度現況
GET /api/v1/organizations/{organizationPk}/credit-quota-inboxes/
參數
organizationPk
✅
string
A UUID string identifying this 組織 ID
ordering
❌
string
Which field to use when ordering the results.
page
❌
integer
A page number within the paginated result set.
pageSize
❌
integer
Number of results to return per page.
search
❌
string
A search term.
程式碼範例
回應內容
狀態碼: 200
回應結構範例
回應範例值
列出成員的額度設定
GET /api/v1/organizations/{organizationPk}/members/{memberPk}/credit-quotas/
參數
memberPk
✅
string
organizationPk
✅
string
A UUID string identifying this 組織 ID
page
❌
integer
A page number within the paginated result set.
pageSize
❌
integer
Number of results to return per page.
程式碼範例
回應內容
狀態碼: 200
回應結構範例
回應範例值
取得成員的單筆額度設定
GET /api/v1/organizations/{organizationPk}/members/{memberPk}/credit-quotas/{id}/
參數
id
✅
string
memberPk
✅
string
organizationPk
✅
string
A UUID string identifying this 組織 ID
程式碼範例
回應內容
狀態碼: 200
回應結構範例
回應範例值
為成員設定額度
POST /api/v1/organizations/{organizationPk}/members/{memberPk}/credit-quotas/
參數
memberPk
✅
string
organizationPk
✅
string
A UUID string identifying this 組織 ID
程式碼範例
回應內容
狀態碼: 201
回應結構範例
回應範例值
更新成員的額度設定
PATCH /api/v1/organizations/{organizationPk}/members/{memberPk}/credit-quotas/{id}/
參數
id
✅
string
memberPk
✅
string
organizationPk
✅
string
A UUID string identifying this 組織 ID
程式碼範例
回應內容
狀態碼: 200
回應結構範例
回應範例值
停用成員的額度設定
DELETE /api/v1/organizations/{organizationPk}/members/{memberPk}/credit-quotas/{id}/
參數
id
✅
string
memberPk
✅
string
organizationPk
✅
string
A UUID string identifying this 組織 ID
程式碼範例
回應內容
204
No response body
列出角色的額度設定
GET /api/v1/organizations/{organizationPk}/groups/{groupPk}/credit-quotas/
參數
groupPk
✅
string
organizationPk
✅
string
A UUID string identifying this 組織 ID
page
❌
integer
A page number within the paginated result set.
pageSize
❌
integer
Number of results to return per page.
程式碼範例
回應內容
狀態碼: 200
回應結構範例
回應範例值
取得角色的單筆額度設定
GET /api/v1/organizations/{organizationPk}/groups/{groupPk}/credit-quotas/{id}/
參數
groupPk
✅
string
id
✅
string
organizationPk
✅
string
A UUID string identifying this 組織 ID
程式碼範例
回應內容
狀態碼: 200
回應結構範例
回應範例值
為角色設定額度
POST /api/v1/organizations/{organizationPk}/groups/{groupPk}/credit-quotas/
參數
groupPk
✅
string
organizationPk
✅
string
A UUID string identifying this 組織 ID
程式碼範例
回應內容
狀態碼: 201
回應結構範例
回應範例值
更新角色的額度設定
PATCH /api/v1/organizations/{organizationPk}/groups/{groupPk}/credit-quotas/{id}/
參數
groupPk
✅
string
id
✅
string
organizationPk
✅
string
A UUID string identifying this 組織 ID
程式碼範例
回應內容
狀態碼: 200
回應結構範例
回應範例值
停用角色的額度設定
DELETE /api/v1/organizations/{organizationPk}/groups/{groupPk}/credit-quotas/{id}/
參數
groupPk
✅
string
id
✅
string
organizationPk
✅
string
A UUID string identifying this 組織 ID
程式碼範例
回應內容
204
No response body
設定角色是否需要額度
PATCH /api/v1/organizations/{organizationPk}/credit-quota-groups/{id}/credit-quota-required/
參數
id
✅
string
A UUID string identifying this Group.
organizationPk
✅
string
A UUID string identifying this 組織 ID
程式碼範例
回應內容
狀態碼: 200
回應結構範例
回應範例值
查詢角色成員額度統計
GET /api/v1/organizations/{organizationPk}/groups/{id}/credit-quota-stats/
參數
id
✅
string
A UUID string identifying this Group.
organizationPk
✅
string
A UUID string identifying this 組織 ID
程式碼範例
回應內容
狀態碼: 200
回應結構範例
回應範例值
依角色批次分配額度
POST /api/v1/organizations/{organizationPk}/groups/{id}/batch-distribute-credit-quota/
參數
id
✅
string
A UUID string identifying this Group.
organizationPk
✅
string
A UUID string identifying this 組織 ID
請求內容
請求參數
name
string
是
canCreateChatbot
boolean
否
canCreateKnowledgeBase
boolean
否
canCreateInbox
boolean
否
canCreateDatabase
boolean
否
canCreateTool
boolean
否
canCreateAgentUiTool
boolean
否
canCreateSkill
boolean
否
maigptCanCodeInterpreter
boolean
否
Whether members of this role may use the code interpreter built-in tool in MaiGPT.
maigptCanRag
boolean
否
Whether members of this role may use the knowledge base RAG built-in tool in MaiGPT.
maigptCanDeepResearch
boolean
否
Whether members of this role may use Deep Research in MaiGPT. Deep Research reaches the public internet through its own built-in search, so a role that revokes the official web-search tools needs this...
maigptCanBrowserTool
boolean
否
Whether members of this role may use the browser built-in tool in MaiGPT.
maigptAllLlms
boolean
否
Whether members of this role may use every organization-available LLM in MaiGPT. Off = only the bound LLMs; an empty binding then means none.
maigptAllTools
boolean
否
Whether members of this role may call every official (global) tool in MaiGPT. Off = only the bound tools; an empty binding then means none.
maigptAllConnectors
boolean
否
Whether members of this role may call every official (global) MCP connector in MaiGPT. Off = only the bound connectors; an empty binding then means none.
maigptAllSkills
boolean
否
Whether members of this role may use every official (global) skill in MaiGPT. Off = only the bound skills; an empty binding then means none.
usageStatisticsScope
object
否
What this role's usage statistics permission shows: the whole organization, or only the AI assistants granted to the member's roles. A member with any organization-wide granting role sees the whole or...
請求結構範例
請求範例值
程式碼範例
回應內容
狀態碼: 200
回應結構範例
回應範例值
依角色批次停用額度
POST /api/v1/organizations/{organizationPk}/groups/{id}/batch-deactivate-credit-quota/
參數
id
✅
string
A UUID string identifying this Group.
organizationPk
✅
string
A UUID string identifying this 組織 ID
請求內容
請求參數
name
string
是
canCreateChatbot
boolean
否
canCreateKnowledgeBase
boolean
否
canCreateInbox
boolean
否
canCreateDatabase
boolean
否
canCreateTool
boolean
否
canCreateAgentUiTool
boolean
否
canCreateSkill
boolean
否
maigptCanCodeInterpreter
boolean
否
Whether members of this role may use the code interpreter built-in tool in MaiGPT.
maigptCanRag
boolean
否
Whether members of this role may use the knowledge base RAG built-in tool in MaiGPT.
maigptCanDeepResearch
boolean
否
Whether members of this role may use Deep Research in MaiGPT. Deep Research reaches the public internet through its own built-in search, so a role that revokes the official web-search tools needs this...
maigptCanBrowserTool
boolean
否
Whether members of this role may use the browser built-in tool in MaiGPT.
maigptAllLlms
boolean
否
Whether members of this role may use every organization-available LLM in MaiGPT. Off = only the bound LLMs; an empty binding then means none.
maigptAllTools
boolean
否
Whether members of this role may call every official (global) tool in MaiGPT. Off = only the bound tools; an empty binding then means none.
maigptAllConnectors
boolean
否
Whether members of this role may call every official (global) MCP connector in MaiGPT. Off = only the bound connectors; an empty binding then means none.
maigptAllSkills
boolean
否
Whether members of this role may use every official (global) skill in MaiGPT. Off = only the bound skills; an empty binding then means none.
usageStatisticsScope
object
否
What this role's usage statistics permission shows: the whole organization, or only the AI assistants granted to the member's roles. A member with any organization-wide granting role sees the whole or...
請求結構範例
請求範例值
程式碼範例
回應內容
狀態碼: 200
回應結構範例
回應範例值
列出對話平台的額度設定
GET /api/v1/inboxes/{inboxPk}/credit-quotas/
參數
inboxPk
✅
string
page
❌
integer
A page number within the paginated result set.
pageSize
❌
integer
Number of results to return per page.
程式碼範例
回應內容
狀態碼: 200
回應結構範例
回應範例值
取得對話平台的單筆額度設定
GET /api/v1/inboxes/{inboxPk}/credit-quotas/{id}/
參數
id
✅
string
inboxPk
✅
string
程式碼範例
回應內容
狀態碼: 200
回應結構範例
回應範例值
為對話平台設定額度
POST /api/v1/inboxes/{inboxPk}/credit-quotas/
參數
inboxPk
✅
string
程式碼範例
回應內容
狀態碼: 201
回應結構範例
回應範例值
更新對話平台的額度設定
PATCH /api/v1/inboxes/{inboxPk}/credit-quotas/{id}/
參數
id
✅
string
inboxPk
✅
string
程式碼範例
回應內容
狀態碼: 200
回應結構範例
回應範例值
停用對話平台的額度設定
DELETE /api/v1/inboxes/{inboxPk}/credit-quotas/{id}/
參數
id
✅
string
inboxPk
✅
string
程式碼範例
回應內容
204
No response body
設定對話平台是否需要額度
PATCH /api/v1/organizations/{organizationPk}/credit-quota-inboxes/{id}/credit-quota-required/
參數
id
✅
string
organizationPk
✅
string
A UUID string identifying this 組織 ID
程式碼範例
回應內容
狀態碼: 200
回應結構範例
回應範例值
查詢自己的額度
GET /api/v1/organizations/{organizationPk}/me/credit-quota/
參數
organizationPk
✅
string
A UUID string identifying this 組織 ID
程式碼範例
回應內容
200
No response body
查詢自己所屬角色的額度
GET /api/v1/organizations/{organizationPk}/me/group-credit-quotas/
參數
organizationPk
✅
string
A UUID string identifying this 組織 ID
程式碼範例
回應內容
200
No response body
列出計價規則
GET /api/v1/credit/pricing-rules/
程式碼範例
回應內容
狀態碼: 200
回應結構範例
回應範例值
取得單一計價規則
GET /api/v1/credit/pricing-rules/{id}/
參數
id
✅
string
A UUID string identifying this Credit Pricing Rule.
程式碼範例
回應內容
狀態碼: 200
回應結構範例
回應範例值
列出計價項目
GET /api/v1/credit/items/
程式碼範例
回應內容
狀態碼: 200
回應結構範例
回應範例值
取得單一計價項目
GET /api/v1/credit/items/{id}/
參數
id
✅
string
A UUID string identifying this Credit Item.
程式碼範例
回應內容
狀態碼: 200
回應結構範例
回應範例值
最後更新於
這有幫助嗎?