|
| 1 | +{ |
| 2 | + "openapi": "3.0.0", |
| 3 | + "info": { |
| 4 | + "title": "AIML API", |
| 5 | + "version": "1.0.0" |
| 6 | + }, |
| 7 | + "servers": [ |
| 8 | + { |
| 9 | + "url": "https://api.aimlapi.com" |
| 10 | + } |
| 11 | + ], |
| 12 | + "paths": { |
| 13 | + "/v2/usage/detail": { |
| 14 | + "get": { |
| 15 | + "operationId": "_v2_usage_detail", |
| 16 | + "parameters": [ |
| 17 | + { |
| 18 | + "name": "period", |
| 19 | + "in": "query", |
| 20 | + "required": false, |
| 21 | + "description": "Relative window: a positive integer followed by `h` or `d`, for example `24h` or `7d`. Provide either `period` or both `start` and `end`, never both.", |
| 22 | + "schema": { |
| 23 | + "type": "string", |
| 24 | + "example": "7d" |
| 25 | + } |
| 26 | + }, |
| 27 | + { |
| 28 | + "name": "start", |
| 29 | + "in": "query", |
| 30 | + "required": false, |
| 31 | + "description": "Window start, ISO-8601. A value without a UTC offset is read as UTC. Must be used together with `end`.", |
| 32 | + "schema": { |
| 33 | + "type": "string", |
| 34 | + "example": "2026-07-01T00:00:00Z" |
| 35 | + } |
| 36 | + }, |
| 37 | + { |
| 38 | + "name": "end", |
| 39 | + "in": "query", |
| 40 | + "required": false, |
| 41 | + "description": "Window end, ISO-8601. Must not be earlier than `start`, and the window must not exceed 92 days.", |
| 42 | + "schema": { |
| 43 | + "type": "string", |
| 44 | + "example": "2026-07-28T00:00:00Z" |
| 45 | + } |
| 46 | + }, |
| 47 | + { |
| 48 | + "name": "key_prefix", |
| 49 | + "in": "query", |
| 50 | + "required": false, |
| 51 | + "description": "Prefix of the key to report on. Omit it to get the spend of the key you are authenticating with. Reporting on a different key requires a management key.", |
| 52 | + "schema": { |
| 53 | + "type": "string", |
| 54 | + "example": "abcd1234" |
| 55 | + } |
| 56 | + } |
| 57 | + ], |
| 58 | + "responses": { |
| 59 | + "200": { |
| 60 | + "content": { |
| 61 | + "application/json": { |
| 62 | + "schema": { |
| 63 | + "type": "object", |
| 64 | + "properties": { |
| 65 | + "api_key_prefix": { |
| 66 | + "type": "string", |
| 67 | + "nullable": true, |
| 68 | + "description": "The requested key prefix, or null when it was omitted and the answer is your own key's spend.", |
| 69 | + "example": "abcd1234" |
| 70 | + }, |
| 71 | + "start": { |
| 72 | + "type": "string", |
| 73 | + "description": "Window start, resolved to UTC.", |
| 74 | + "example": "2026-07-20T22:15:00.000Z" |
| 75 | + }, |
| 76 | + "end": { |
| 77 | + "type": "string", |
| 78 | + "description": "Window end, resolved to UTC.", |
| 79 | + "example": "2026-07-27T22:15:00.000Z" |
| 80 | + }, |
| 81 | + "spend": { |
| 82 | + "type": "number", |
| 83 | + "description": "Total spend for the key over the window, in USD. This is the authoritative total: it is computed from the total, not by adding up models, so it can differ from that sum by a few nano-dollars.", |
| 84 | + "example": 12.3456 |
| 85 | + }, |
| 86 | + "currency": { |
| 87 | + "type": "string", |
| 88 | + "description": "Spend currency (always USD).", |
| 89 | + "example": "USD" |
| 90 | + }, |
| 91 | + "requests": { |
| 92 | + "type": "integer", |
| 93 | + "description": "Number of charged requests in the window.", |
| 94 | + "example": 842 |
| 95 | + }, |
| 96 | + "models": { |
| 97 | + "type": "array", |
| 98 | + "description": "Per-model breakdown, highest spend first.", |
| 99 | + "items": { |
| 100 | + "type": "object", |
| 101 | + "properties": { |
| 102 | + "model": { |
| 103 | + "type": "string", |
| 104 | + "description": "Model name.", |
| 105 | + "example": "openai/gpt-5" |
| 106 | + }, |
| 107 | + "spend": { |
| 108 | + "type": "number", |
| 109 | + "description": "Spend for this model, in USD.", |
| 110 | + "example": 8.12 |
| 111 | + }, |
| 112 | + "requests": { |
| 113 | + "type": "integer", |
| 114 | + "description": "Charged requests for this model.", |
| 115 | + "example": 500 |
| 116 | + } |
| 117 | + }, |
| 118 | + "required": ["model", "spend", "requests"] |
| 119 | + } |
| 120 | + } |
| 121 | + }, |
| 122 | + "required": [ |
| 123 | + "api_key_prefix", |
| 124 | + "start", |
| 125 | + "end", |
| 126 | + "spend", |
| 127 | + "currency", |
| 128 | + "requests", |
| 129 | + "models" |
| 130 | + ] |
| 131 | + } |
| 132 | + } |
| 133 | + } |
| 134 | + } |
| 135 | + }, |
| 136 | + "x-hideTryItPanel": true, |
| 137 | + "x-codeSamples": [ |
| 138 | + { |
| 139 | + "lang": "cURL", |
| 140 | + "source": "curl -L \\\n --request GET \\\n --url 'https://api.aimlapi.com/v2/usage/detail?key_prefix=abcd1234&period=7d' \\\n --header 'Authorization: Bearer <YOUR_AIMLAPI_MANAGEMENT_KEY>'" |
| 141 | + }, |
| 142 | + { |
| 143 | + "lang": "JavaScript", |
| 144 | + "source": "async function main() {\n const url = new URL(\"https://api.aimlapi.com/v2/usage/detail\");\n url.searchParams.set(\"key_prefix\", \"abcd1234\");\n url.searchParams.set(\"period\", \"7d\");\n\n const response = await fetch(url, {\n headers: {\n \"Authorization\": \"Bearer <YOUR_AIMLAPI_MANAGEMENT_KEY>\",\n },\n });\n\n const data = await response.json();\n console.log(JSON.stringify(data, null, 2));\n}\n\nmain();" |
| 145 | + }, |
| 146 | + { |
| 147 | + "lang": "Python", |
| 148 | + "source": "import requests\nimport json\n\ndef main():\n response = requests.get(\n \"https://api.aimlapi.com/v2/usage/detail\",\n headers={\n # Insert your AIML API management key instead of <YOUR_AIMLAPI_MANAGEMENT_KEY>:\n \"Authorization\": \"Bearer <YOUR_AIMLAPI_MANAGEMENT_KEY>\",\n },\n params={\"key_prefix\": \"abcd1234\", \"period\": \"7d\"}\n )\n\n data = response.json()\n print(json.dumps(data, indent=2, ensure_ascii=False))\n\nif __name__ == \"__main__\":\n main()" |
| 149 | + } |
| 150 | + ] |
| 151 | + } |
| 152 | + } |
| 153 | + }, |
| 154 | + "components": { |
| 155 | + "securitySchemes": { |
| 156 | + "access-token": { |
| 157 | + "scheme": "bearer", |
| 158 | + "bearerFormat": "<YOUR_AIMLAPI_KEY>", |
| 159 | + "type": "http", |
| 160 | + "description": "Bearer key" |
| 161 | + } |
| 162 | + } |
| 163 | + } |
| 164 | +} |
0 commit comments