Skip to content

Commit 8dd5b54

Browse files
nagautadehesa
authored andcommitted
add check open api usage
1 parent 41ac384 commit 8dd5b54

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
# Required parameters:
4+
# @raycast.schemaVersion 1
5+
# @raycast.title Check Usage of OpenAI API
6+
# @raycast.mode inline
7+
# @raycast.packageName System
8+
9+
#
10+
# Optional parameters:
11+
# @raycast.icon 💲
12+
#
13+
# Documentation:
14+
# @raycast.description Get total usage of OpenAI API
15+
# @raycast.author nagauta
16+
# @raycast.authorURL https://github.com/nagauta
17+
18+
_ORGANIZATION=""
19+
_OPENAI_APIKEY=""
20+
21+
_START_DATE="$(date -u +'%Y-%m')-01"
22+
_END_DATE="$(date -u -v+1m +'%Y-%m')-01"
23+
echo
24+
TOTAL_USAGE=$(curl -sSf "https://api.openai.com/dashboard/billing/usage?end_date=${_END_DATE}&start_date=${_START_DATE}" \
25+
-H "authorization: Bearer ${_OPENAI_APIKEY}" \
26+
| jq -r '"$" + (.total_usage | round / 100 | tostring)')
27+
28+
echo "Total Usage: ${TOTAL_USAGE}, Period: ${_START_DATE}-${_END_DATE}"

0 commit comments

Comments
 (0)