# Hreflang Checker - Validate hreflang Tags (`devoted_laureate_r8f/audit-hreflang`) Actor

Check the hreflang tags of any public page: invalid language/region codes, duplicates, missing x-default, missing self-reference and optional reciprocity (return-link) checks. One clear report per page.

- **URL**: https://apify.com/devoted_laureate_r8f/audit-hreflang.md
- **Developed by:** [Billy Zouz](https://apify.com/devoted_laureate_r8f) (community)
- **Categories:** SEO tools, Developer tools
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$5.00 / 1,000 page auditeds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Hreflang Tag Auditor

Fetches a single public URL, extracts all `hreflang` alternate-link annotations from its HTML, and
validates them for common international SEO mistakes: duplicate language codes, invalid BCP47 tags,
a missing `x-default` fallback, and a missing self-reference. Optionally fetches a limited number of
the referenced alternate URLs to check that they link back ("reciprocate") to the original page.

### What it does

1. Downloads the HTML of the page given in `url`.
2. Parses every `<link rel="alternate" hreflang="...">` tag and resolves its `href` to an absolute URL.
3. Checks the extracted set for:
   - a `hreflang="x-default"` fallback annotation,
   - a self-referencing annotation (the page listing itself),
   - duplicate language codes,
   - hreflang values that are not syntactically valid BCP47 language tags.
4. If `checkReciprocity` is enabled, fetches up to `maxAlternates` of the alternate URLs and verifies
   each one links back to the original page via its own hreflang set.
5. Returns a structured report plus a human-readable list of issues.

### Input

| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| `url` | string | yes | — | Public URL of the page to audit. |
| `checkReciprocity` | boolean | no | `false` | Fetch each alternate URL found to verify it links back to the original page. |
| `maxAlternates` | integer | no | `10` | Maximum number of alternate URLs to fetch when checking reciprocity (capped at 50). |

### Output

One dataset row per run:

| Field | Description |
|---|---|
| `input` | The audited URL. |
| `ok` | Whether the audit completed successfully. |
| `error` | Error message when `ok` is `false` (e.g. the URL could not be fetched), `null` otherwise. |
| `result.url` | URL of the audited page. |
| `result.alternates` | List of `{ hreflang, href }` pairs extracted from the page. |
| `result.hasXDefault` | Whether an `x-default` annotation is present. |
| `result.selfReferencing` | Whether the page references its own URL in its hreflang set. |
| `result.duplicateLangCodes` | Language codes that appear more than once. |
| `result.invalidLangCodes` | Hreflang values that are not valid BCP47 tags. |
| `result.reciprocityResults` | Per-alternate `{ href, reciprocal, error? }`, or `null` if `checkReciprocity` was off. |
| `result.issues` | Human-readable list of detected problems. |

### Pricing

Pay per event: **$0.005 per page audited**. One page's hreflang annotations fetched and fully validated (charged even when no issue is found: the report is complete).

You only pay for these events: the platform usage of the run is covered by the Actor. Failed fetches are not charged. You can cap the cost of a run with the maximum charge setting of your run.

### Limits

- Audits one URL per run; only public pages are supported (no login, no paywalled content).
- Fetches time out after 15 seconds.
- `maxAlternates` is capped at 50 to limit the number of outbound requests per run.
- Reciprocity checking issues a GET request to every selected alternate URL; disable it if you only
  need the on-page hreflang extraction and validation.
- No personal data is collected or stored.

### Use in your workflow

Replace `<APIFY_TOKEN>` with your token from Apify Console → Settings → API & Integrations.

**HTTP API (curl)** — run and get the results in one call:

```bash
curl -X POST "https://api.apify.com/v2/acts/devoted_laureate_r8f~audit-hreflang/run-sync-get-dataset-items" \
  -H "Authorization: Bearer <APIFY_TOKEN>" -H "Content-Type: application/json" \
  -d '{"url": "https://www.apple.com/", "checkReciprocity": false, "maxAlternates": 10}'
```

**JavaScript** (`npm install apify-client`):

```js
import { ApifyClient } from 'apify-client';

const client = new ApifyClient({ token: process.env.APIFY_TOKEN });
const run = await client.actor('devoted_laureate_r8f/audit-hreflang').call({"url": "https://www.apple.com/", "checkReciprocity": false, "maxAlternates": 10});
const { items } = await client.dataset(run.defaultDatasetId).listItems();
console.log(items);
```

**Python** (`pip install apify-client`):

```python
import os
from apify_client import ApifyClient

client = ApifyClient(os.environ["APIFY_TOKEN"])
run = client.actor("devoted_laureate_r8f/audit-hreflang").call(run_input={"url": "https://www.apple.com/", "checkReciprocity": False, "maxAlternates": 10})
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)
```

**AI agents (MCP)** — expose only this Actor as a tool through the Apify MCP server:

```json
{
  "mcpServers": {
    "hreflang-tag-checker": {
      "url": "https://mcp.apify.com?tools=devoted_laureate_r8f/audit-hreflang",
      "headers": {
        "Authorization": "Bearer <APIFY_TOKEN>"
      }
    }
  }
}
```

For agents: call it when you need to validate the hreflang (international SEO) annotations of a web page. Input: `url` (one page); optional `checkReciprocity` and `maxAlternates`. Output: one record with the hreflang entries found and the list of issues (invalid codes, duplicates, missing x-default or self-reference, missing return links). Cost: $0.005 per page audited; failures are not charged.

### FAQ

**What does a hreflang error look like?**

Typical problems are invalid language or region codes (for example en-UK instead of en-GB), the same language listed twice, a missing x-default, or a page that does not reference itself. The report lists each one with the offending value.

**What is reciprocity?**

Every alternate page should link back to the original. With 'Check reciprocity' on, the Actor fetches up to 'Max alternates' referenced pages and reports which ones do not return the link.

**Am I charged if no problem is found?**

Yes, one event per page audited: you still get a complete, validated list of the page's hreflang annotations.

### Related tools

- [Broken Link Checker - Find Dead Links on a Page](https://apify.com/devoted_laureate_r8f/broken-link-checker) — alternate URLs that return 404 break hreflang
- [Canonical Tag Checker - Bulk Canonical URL Audit](https://apify.com/devoted_laureate_r8f/canonical-tag-checker) — hreflang and canonical tags must point to the same indexable URLs

# Actor input Schema

## `url` (type: `string`):

Public URL of the page to audit.

## `checkReciprocity` (type: `boolean`):

If true, fetches each alternate URL found on the page to verify it links back to the original page.

## `maxAlternates` (type: `integer`):

Maximum number of alternate URLs to fetch when checking reciprocity (capped at 50).

## Actor input object example

```json
{
  "checkReciprocity": false,
  "maxAlternates": 10
}
```

# Actor output Schema

## `results` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("devoted_laureate_r8f/audit-hreflang").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("devoted_laureate_r8f/audit-hreflang").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call devoted_laureate_r8f/audit-hreflang --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,devoted_laureate_r8f/audit-hreflang"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/kVurawGywgDZG73xt/builds/SBieVlS51WpZUehzk/openapi.json
