News API

data newsapi

News API

Headlines from 80,000+ worldwide sources.

Quick Facts

FieldValue
ProviderNews API
CategoryData & Storage APIs
Websitehttps://newsapi.org
AuthenticationAPI Key
Pricing Modelfreemium
Tagsnews, media, content

Authentication

This API uses API Key authentication. Refer to the official documentation at https://newsapi.org.

Pricing

The pricing model is freemium. Visit the provider’s pricing page for current rates.

Code Samples

Python

import requests

API_KEY = "YOUR_API_KEY"
BASE_URL = "https://newsapi.org"

headers = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json"
}

response = requests.get(BASE_URL, headers=headers)
print(response.status_code)
print(response.json())

JavaScript (Node.js)

const API_KEY = process.env.API_KEY || "YOUR_API_KEY";
const BASE_URL = "https://newsapi.org";

async function callApi() {
  const response = await fetch(BASE_URL, {
    headers: {
      "Authorization": `Bearer ${API_KEY}`,
      "Content-Type": "application/json"
    }
  });
  const data = await response.json();
  console.log(data);
}

callApi();

Go

package main

import (
    "fmt"
    "io"
    "net/http"
    "os"
)

func main() {
    apiKey := os.Getenv("API_KEY")
    if apiKey == "" {
        apiKey = "YOUR_API_KEY"
    }
    req, _ := http.NewRequest("GET", "https://newsapi.org", nil)
    req.Header.Set("Authorization", "Bearer "+apiKey)
    req.Header.Set("Content-Type", "application/json")
    resp, err := http.DefaultClient.Do(req)
    if err != nil {
        fmt.Println("Error:", err)
        return
    }
    defer resp.Body.Close()
    body, _ := io.ReadAll(resp.Body)
    fmt.Println(string(body))
}

cURL

curl -X GET "https://newsapi.org" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json"

Best Practices

  • Never hardcode API keys in source code
  • Respect rate limits, implement exponential backoff
  • Validate responses
  • Cache when possible
  • Use webhooks for async workflows
  • Log request IDs for debugging

Browse other APIs in Data & Storage APIs or all APIs from News API.

Other languages