The User Agent API provides endpoints to parse and generate user agent strings.
For user agent parsing, see /v1/useragentparse.
For user agent generation, see /v1/useragentgenerate.
https://api.api-ninjas.com/v1/useragentparse
Parses a user agent string to extract device, operating system, and browser information.
useragent
requiredUser agent string to parse.
X-Api-Key
requiredAPI Key associated with your account.
https://api.api-ninjas.com/v1/useragentparse?useragent=Mozilla%2F5.0%20(Macintosh%3B%20Intel%20Mac%20OS%20X%2010_9_4)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F41.0.2272.104%20Safari%2F537.36
Headers
X-Api-Key
Log in or sign up to get your API Key
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
{
"browser": {
"family": "Chrome",
"version": "41.0.2272"
},
"os": {
"family": "Mac OS X",
"version": "10.9.4"
},
"device": {
"family": "Mac",
"brand": "Apple",
"model": "Mac"
},
"is_mobile": true,
"is_tablet": false,
"is_pc": false,
"is_bot": false
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import requests
# Parse user agent
useragent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.104 Safari/537.36'
api_url = 'https://api.api-ninjas.com/v1/useragentparse?useragent={}'.format(useragent)
response = requests.get(api_url, headers={'X-Api-Key': 'YOUR_API_KEY'})
if response.status_code == requests.codes.ok:
print(response.text)
else:
print("Error:", response.status_code, response.text)
# Generate user agent
api_url = 'https://api.api-ninjas.com/v1/useragentgenerate?os=windows&browser=chrome'
response = requests.get(api_url, headers={'X-Api-Key': 'YOUR_API_KEY'})
if response.status_code == requests.codes.ok:
print(response.text)
else:
print("Error:", response.status_code, response.text)
If your programming language is not listed in the Code Example above, you can still make API calls by using a HTTP request library written in your programming language and following the above documentation.
https://api.api-ninjas.com/v1/useragentgenerate
Generates a realistic user agent string based on optional parameters.
brand
optionalDevice brand (e.g. Apple
, Samsung
)
model
optionalDevice model (e.g. iPhone
, Galaxy
)
os
optionalOperating system (e.g. Windows
, iOS
, Android
)
browser
optionalBrowser name (e.g. Chrome
, Firefox
, Safari
)
https://api.api-ninjas.com/v1/useragentgenerate?os=Windows&browser=Chrome
1
2
3
{
"user_agent": "Mozilla/5.0 (Windows 10.0; Apple iPhone 14) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0 Safari/537.36"
}