I've been using Python to access data on VirusTotal with my public api keys.
I wondered if it's possible to see the quota usage using Python. I know I can see the data by logging into my VirusTotal account, but if I can see the usage when running my script that would be easier to keep track.
What you are looking for is probably the user-api-usage endpoint.
According to the linked api-docs, the JSON
object returned is of the format:
{
"data": {
"daily": {
"2020-08-10": {
"urls": 2
},
"2020-08-11": {
"domains": 1,
"file_relationships": 1,
"files": 1
},
"2020-08-12": {
"analyses": 25,
"file_analyse": 3,
"files": 6
},
"2020-08-17": {
"urls": 3
},
"2020-08-18": {
"urls": 1
},
"2020-08-20": {
"file_download": 36,
"file_relationships": 5,
"files": 1
},
"2020-08-21": {
"file_analyse": 1,
"file_download": 92,
"files": 1
},
"2020-08-23": {
"analyses": 5,
"file_analyse": 1
},
"2020-08-25": {
"file_download": 51
},
"2020-08-26": {
"file_download": 51
},
"2020-08-28": {
"file_download": 14
},
"2020-08-31": {
"file_download": 6
},
"2020-09-01": {
"file_download": 81
},
"2020-09-02": {
"file_relationships": 5,
"graphs": 1
},
"2020-09-03": {
"file_relationships": 6,
"graph_comments": 1,
"graph_items": 3,
"graphs": 2,
"retrohunt_jobs": 2
},
{
...
}
},
"total": {
"analyses": 30,
"comment_relationships": 1,
"comments": 4,
"domain_comments": 1,
"domain_graphs": 2,
"domain_relationships": 2,
"domains": 1,
"file_analyse": 6,
"file_behaviours": 6,
"file_download": 331,
"file_relationships": 19,
"files": 9,
"graph_comments": 2,
"graph_items": 3,
"graphs": 8,
"intelligence_search": 5,
"resolutions": 1,
"retrohunt_jobs": 2,
"search": 6,
"statistics": 1,
"submissions": 1,
"url_relationships": 1,
"urls": 8
}
}
}
Which gives you both a by-date breakdown and a "totals" node at the bottom of the stream/file.
The command that the documentation recommends is as follows:
curl --request GET \
--url https://www.virustotal.com/api/v3/users/{id}/api_usage \
--header 'x-apikey: <your API key>'
Again, the source for this info is linked above.
EDIT:
A python function commonly used to run shell commands like curl
is the system.os()
function. There are other (and possibly even better) solutions for this, but that is out of scope for this answer. To use it in your script, you would add:
/usr/bin/env python
import system
...
system.os('curl --request GET --url https://www.virustotal.com/api/v3/users/{id}/api_usage --header \'x-apikey: <your API key>\'')
...to your script (Notice the added backslashes escaping the inner quotes.)