User Agent API
The User Agent API provides endpoints to parse and generate user agent strings.
Available endpoints:
- /v2/useragentparse - Parse a user agent string to validate and extract device, operating system, and browser information.
- /v1/useragentgenerate - Generate random user agent strings
From 6,328 users
Applications using this API
API Status
API Response Times
Average | P50 | P75 | P90 | P95 |
|---|---|---|---|---|
| 348ms | 368ms | 423ms | 623ms | 1134ms |
Didn't find what you were looking for? Suggest an improvement
/v2/useragentparse GET
https://api.api-ninjas.com/v2/useragentparse
Parses a user agent string to extract device, operating system, and browser information. All response fields are top-level. Invalid or unrecognized user agents return HTTP 200 with is_valid: false and invalid_reason set; data fields are null in that case.
Parameters
useragentrequiredUser agent string to parse.
Headers
X-Api-KeyrequiredAPI Key associated with your account.
Response
A JSON object with the following top-level fields. On success is_valid is true and all data fields are populated. On invalid user agent is_valid is false, invalid_reason contains the reason, and data fields are null. invalid_reason is always present (empty string when valid).
browser_familyBrowser name.
browser_versionBrowser version.
os_familyOperating system name.
os_versionOperating system version.
device_familyDevice family (e.g. Other, iPhone, Samsung SM-G991B).
device_brandDevice brand.
device_modelDevice model.
device_typeOne of
computer,tablet, ormobile.is_validWhether the user agent passed validation.
invalid_reasonAlways present. Empty string when valid; when
is_validisfalse, describes why the user agent was rejected.
Sample Request Live Demo!
Try our APIs in the API playground
Sign up for a free API key to get started — no credit card required.
https://api.api-ninjas.com/v2/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.36Headers
X-Api-KeyLog in or sign up to get your API KeySample Response
Code Examples
1
2
3
4
5
6
7
# Parse user agent
curl -X GET "https://api.api-ninjas.com/v2/useragentparse?useragent=Mozilla%2F5.0%20%28Macintosh%3B%20Intel%20Mac%20OS%20X%2010_9_4%29%20AppleWebKit%2F537.36%20%28KHTML%2C%20like%20Gecko%29%20Chrome%2F41.0.2272.104%20Safari%2F537.36" \
-H "X-Api-Key: YOUR_API_KEY"
# Generate user agent
curl -X GET "https://api.api-ninjas.com/v1/useragentgenerate?os=windows&browser=chrome" \
-H "X-Api-Key: YOUR_API_KEY"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.
/v1/useragentgenerate GET
https://api.api-ninjas.com/v1/useragentgenerate
Generates a realistic user agent string based on optional parameters.
Parameters
brandoptionalDevice brand (e.g.
Apple,Samsung)modeloptionalDevice model (e.g.
iPhone,Galaxy)osoptionalOperating system (e.g.
Windows,iOS,Android)browseroptionalBrowser name (e.g.
Chrome,Firefox,Safari)
Response
A JSON object with the following fields or an error if the request is unsuccessful.
user_agentA randomly generated user agent string matching the specified criteria.
Generate User Agent Sample Request Live Demo!
Try our APIs in the API playground
Sign up for a free API key to get started — no credit card required.
https://api.api-ninjas.com/v1/useragentgenerate?os=windows&browser=chromeHeaders
X-Api-KeyLog in or sign up to get your API KeyGenerate User Agent Sample Response
Frequently Asked Questions
Can I use the User Agent API for commercial purposes?
Yes, but you must have a premium subscription. Commercial use of the User Agent API is not permitted on the free tier. See our pricing page to choose a plan that fits your needs.How do I get an API key and start using the User Agent API?
Sign up for a free account to instantly get your API key, then pass it in theX-Api-Keyheader on every request. The documentation above includes ready-to-run examples in cURL, Python, JavaScript, Node.js, and more.What happens if I exceed my quota for the month?
Your API requests will simply be denied once you hit your monthly quota — you will never be charged more than the plan you signed up for. To increase your quota, you can upgrade your plan any time on our pricing page.What happens if a request to the User Agent API fails?
The API responds with a standard HTTP status code and a JSON error message describing the problem. See our error codes reference for the full list of codes and how to resolve each one, or contact support if you need help.What is the difference between the two User Agent API endpoints?
The API exposes two endpoints:/v2/useragentparsetakes auseragentstring and extracts device, OS, and browser details, while/v1/useragentgeneratebuilds a realistic random user agent string from optionalbrand,model,os, andbrowserparameters. See the full API list for related tools.What fields does the parse endpoint return?
A successful/v2/useragentparsecall returns top-level fields includingbrowser_family,browser_version,os_family,os_version,device_family,device_brand,device_model, anddevice_type(one ofcomputer,tablet, ormobile), plusis_validandinvalid_reason. You can try it live or register for a key to start parsing.How does the API handle an invalid or unrecognized user agent string?
Invalid user agents still return HTTP 200 withis_validset tofalseandinvalid_reasondescribing why it was rejected, while the data fields arenull;invalid_reasonis always present and is an empty string when the string is valid. For HTTP-level failures, see our error codes.How do I generate a user agent for a specific device or browser?
Call/v1/useragentgeneratewith any combination of the optionalbrand(e.g.Apple,Samsung),model(e.g.iPhone,Galaxy),os(e.g.Windows,iOS,Android), andbrowser(e.g.Chrome,Firefox,Safari) parameters, and the response returns a matchinguser_agentstring. Check the pricing page for request limits.