OS Detection API: The Complete Guide

Need to identify which operating system your users are on? This guide covers everything you need to know about OS detection via API, including version identification, platform detection, and implementation examples.

What is OS Detection?

OS detection is the process of identifying the operating system and version running on a user's device. This information is typically extracted from the user agent string and helps deliver platform-appropriate experiences and downloads.

Knowing the OS helps provide correct download links, keyboard shortcuts, and platform-specific features.

Major Operating Systems

The most common operating systems detected:

OS Platform Recent Versions
WindowsDesktop11, 10, 8.1
macOSDesktopSonoma, Ventura, Monterey
LinuxDesktop/ServerUbuntu, Fedora, Debian
Chrome OSDesktopVarious versions
iOSMobile17, 16, 15
AndroidMobile14, 13, 12
Pro Tip: Use OS detection to provide the correct download links for desktop applications or to show platform-specific keyboard shortcuts (Cmd vs Ctrl).

Using the OS Detection API

TinyFn provides an endpoint to detect operating system information:

API Request
POST https://api.tinyfn.io/v1/detect/os
Headers: X-API-Key: your-api-key
Content-Type: application/json

{
  "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36"
}
Response
{
  "os": {
    "name": "macOS",
    "version": "10.15.7",
    "version_name": "Catalina",
    "family": "macOS",
    "architecture": "x64"
  },
  "platform": {
    "type": "desktop",
    "vendor": "Apple"
  },
  "is_64bit": true,
  "is_mobile_os": false
}

Parameters

Parameter Type Description
user_agent string User agent string (required)

Code Examples

JavaScript / Node.js

const response = await fetch('https://api.tinyfn.io/v1/detect/os', {
  method: 'POST',
  headers: {
    'X-API-Key': 'your-api-key',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    user_agent: navigator.userAgent
  })
});
const data = await response.json();

// Show appropriate keyboard shortcut
const shortcut = data.os.name === 'macOS' ? 'Cmd+S' : 'Ctrl+S';
console.log(`Press ${shortcut} to save`);

// Set download link
const downloadUrl = `/download/${data.os.name.toLowerCase()}`;

Python

import requests

def detect_os(user_agent):
    response = requests.post(
        'https://api.tinyfn.io/v1/detect/os',
        json={'user_agent': user_agent},
        headers={'X-API-Key': 'your-api-key'}
    )
    return response.json()

# Example usage
os_info = detect_os(request.headers.get('User-Agent'))
print(f"OS: {os_info['os']['name']} {os_info['os']['version']}")
print(f"Platform: {os_info['platform']['type']}")

cURL

curl -X POST "https://api.tinyfn.io/v1/detect/os" \
  -H "X-API-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{"user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"}'

Common Use Cases

  • Download Links: Provide correct installer for each OS
  • Keyboard Shortcuts: Show Cmd on Mac, Ctrl on Windows/Linux
  • Installation Guides: Display OS-specific instructions
  • App Store Links: Link to iOS App Store or Google Play
  • System Requirements: Check if user meets minimum OS requirements

Best Practices

  1. Provide all options: Always show links to other platforms
  2. Handle unknown OS: Have fallback for undetected systems
  3. Consider Linux distros: Linux users expect generic Linux downloads
  4. Test regularly: OS user agent patterns can change

Try the OS Detection API

Get your free API key and start detecting operating systems in seconds.

Get Free API Key

Ready to try TinyFn?

Get your free API key and start building in minutes.

Get Free API Key