Allocate Credits
allocate_creditsAllocate credits to a client by specifying client ID, credit type, amount, source, and notes.
Instructions
Allocate credits to a client.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| client_id | Yes | Client ID | |
| credit_type | Yes | Credit type | |
| amount | Yes | Number of credits | |
| source | No | Source (e.g. bonus) | |
| notes | No | Notes |
Implementation Reference
- server/index.js:1107-1129 (registration)Registration of the 'allocate_credits' tool with title, description, input schema, and annotations.
server.registerTool( "allocate_credits", { title: "Allocate Credits", description: "Allocate credits to a client.", inputSchema: { client_id: z.string().describe("Client ID"), credit_type: z.enum(["monthly", "purchased", "daily"]).describe("Credit type"), amount: z.number().describe("Number of credits"), source: z.string().optional().describe("Source (e.g. bonus)"), notes: z.string().optional().describe("Notes"), }, annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: false }, }, async ({ client_id, credit_type, amount, source, notes }) => { const body = { client_id, credit_type, amount }; if (source) body.source = source; if (notes) body.notes = notes; const data = await apiCall("/v1/ai/credits/client/allocate", "POST", body); const payload = data?.result || data; return { content: [{ type: "text", text: JSON.stringify(payload, null, 2) }] }; } ); - server/index.js:1121-1128 (handler)The async handler function for 'allocate_credits' that constructs the body and calls the API endpoint POST /v1/ai/credits/client/allocate.
async ({ client_id, credit_type, amount, source, notes }) => { const body = { client_id, credit_type, amount }; if (source) body.source = source; if (notes) body.notes = notes; const data = await apiCall("/v1/ai/credits/client/allocate", "POST", body); const payload = data?.result || data; return { content: [{ type: "text", text: JSON.stringify(payload, null, 2) }] }; } - server/index.js:1112-1118 (schema)Input schema for 'allocate_credits': requires client_id (string), credit_type (enum: monthly/purchased/daily), amount (number), with optional source and notes fields.
inputSchema: { client_id: z.string().describe("Client ID"), credit_type: z.enum(["monthly", "purchased", "daily"]).describe("Credit type"), amount: z.number().describe("Number of credits"), source: z.string().optional().describe("Source (e.g. bonus)"), notes: z.string().optional().describe("Notes"), }, - server/index.js:112-123 (helper)The apiCall helper function used by the handler to make authenticated HTTP requests.
async function apiCall(path, method, body) { const url = `${BASE_URL}${path}`; const res = await fetch(url, { method, headers: { Authorization: `Bearer ${API_KEY}`, "Content-Type": "application/json", }, ...(body ? { body: JSON.stringify(body) } : {}), }); return res.json(); }