NewConnect Claude, Gemini, ChatGPT, and other AI agents to API Ninjas via our MCP server

Country Flag API

The Country Flag API provides SVG flag images for any country, territory, or area of special interest (over 250 supported). The small file sizes are perfect for displaying flag icons on your website or populating a dropdown menu.

Available endpoints:

For geographic, demographic and economic statistics on countries, check out the Country API instead.

(4.1)

From 4,004 users

2,600+

Applications using this API

API Status

Online - All Systems Operational

API Response Times

Average
P50
P75
P90
P95
327ms365ms369ms554ms1201ms

Didn't find what you were looking for? Suggest an improvement


/v1/countryflag GET

https://api.api-ninjas.com/v1/countryflag

Get a country's flag as an SVG image in base64 format. Both 1:1 and 4:3 aspect ratios are supported and returned in the response.

Parameters

  • country  required

    2-letter ISO-3166 alpha-2 country code (e.g. US, CA, FR). For countries in the United Kingdom, use GB for Great Britain, GB-ENG for England, GB-SCT for Scotland, GB-WLS for Wales, GB-NIR for Northern Ireland.

Headers

  • X-Api-Key  required

    API Key associated with your account.

Response

A JSON object with the following fields or an error if the request is unsuccessful.

  • country

    2-letter ISO-3166 alpha-2 country code.

  • square_image_url

    URL to the square (1:1) flag image in SVG format.

  • rectangle_image_url

    URL to the rectangle (4:3) flag image in SVG format.

Sample Request Live Demo!

country

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/countryflag?country=US

Headers

X-Api-KeyLog in or sign up to get your API Key

Sample Response

JSON
{
    country:"US",
    square_image_url:"https://api-ninjas-data.s3.us-west-2.amazonaws.com/flags/1x1/KoHP0ZTO/us.svg",
    rectangle_image_url:"https://api-ninjas-data.s3.us-west-2.amazonaws.com/flags/4x3/8L07WqeX/us.svg"
}

Code Examples

1 2 curl -X GET "https://api.api-ninjas.com/v1/countryflag?country=United%20States" \ -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/allcountryflags GETPremium Only

https://api.api-ninjas.com/v1/allcountryflags

Get flag images for all countries. Returns an list of countries and their flag URLs.

Headers

  • X-Api-Key  required

    API Key associated with your account.

Response

A JSON array of objects, each containing the following fields, or an error if the request is unsuccessful.

  • country

    2-letter ISO-3166 alpha-2 country code.

  • square_image_url

    URL to the square (1:1) flag image in SVG format.

  • rectangle_image_url

    URL to the rectangle (4:3) flag image in SVG format.

Sample Request

https://api.api-ninjas.com/v1/allcountryflags

Sample Response

JSON
[
    {
      country:"AD",
      square_image_url:"https://api-ninjas-data.s3.us-west-2.amazonaws.com/flags/1x1/irDOqrgs/ad.svg",
      rectangle_image_url:"https://api-ninjas-data.s3.us-west-2.amazonaws.com/flags/4x3/kSezcqOa/ad.svg"
    },
    {
      country:"AE",
      square_image_url:"https://api-ninjas-data.s3.us-west-2.amazonaws.com/flags/1x1/5RmaAls3/ae.svg",
      rectangle_image_url:"https://api-ninjas-data.s3.us-west-2.amazonaws.com/flags/4x3/g2IOl3w9/ae.svg"
    },
    "..."
]

Frequently Asked Questions

  • Yes, but you must have a premium subscription. Commercial use of the Country Flag API is not permitted on the free tier. See our pricing page to choose a plan that fits your needs.
  • Sign up for a free account to instantly get your API key, then pass it in the X-Api-Key header on every request. The documentation above includes ready-to-run examples in cURL, Python, JavaScript, Node.js, and more.
  • 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.
  • 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.
  • Send a GET request to /v1/countryflag with the required country parameter set to a 2-letter ISO-3166 alpha-2 country code such as US, CA, or FR. For the United Kingdom you can also use sub-codes like GB-ENG for England, GB-SCT for Scotland, GB-WLS for Wales, and GB-NIR for Northern Ireland. See the full API list for related endpoints.
  • Each response returns the country code along with square_image_url (the 1:1 aspect ratio flag) and rectangle_image_url (the 4:3 aspect ratio flag), both pointing to SVG images. If a request is unsuccessful you will receive an error instead.
  • Use the premium-only /v1/allcountryflags endpoint, which returns a JSON array of objects each containing country, square_image_url, and rectangle_image_url for every supported country. This endpoint requires a paid plan, which you can review on the pricing page.
  • Because the SVG flags have small file sizes, they are ideal for displaying flag icons on your website or populating a country dropdown menu, and they cover over 250 countries, territories, and areas of special interest. For geographic, demographic, and economic statistics on countries, pair it with the Country API.