Skip to content

CDN

Edge content distributions, cache purge (by path, tag or everything) and delivery stats across major CDN vendors.

Overview

Base path: https://api.infrai.cc/v1/cdn
Auth header: Authorization: Bearer $INFRAI_API_KEY
bash
# Call any /v1/cdn capability over raw HTTP — no SDK to install.
# curl:
curl https://api.infrai.cc/v1/cdn/... \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json"

Methods

cdn.distribution.create

POST /v1/cdn/distribution/create

Create a CDN distribution (a vendor zone/service/domain) that fronts an origin with an edge cache, returning the CNAME target to point your hostname at.

Parameters

NameTypeRequiredDescription
originstring
Required
Origin host/URL the edge fronts.
domainstringOptionalPublic delivery hostname (CNAME target).
enabledbooleanOptionalWhether the distribution serves traffic.
cache_ttl_secondsnumberOptionalDefault edge cache TTL in seconds.
allowed_methodsstring[]OptionalHTTP methods the edge forwards.
https_onlybooleanOptionalForce HTTPS at the edge.
tagsstring[]OptionalCache-tag / surrogate-key labels.
vendorstringOptionalOptional explicit vendor pin; otherwise resolved by region.

Returns

Distribution { distribution_id, origin, domain, enabled, status }

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at the console: Google/GitHub gives you
# $2 free credit (email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT,
# POST /v1/account/topup and open the returned checkout_url.
export INFRAI_API_KEY="ifr_pk_proj_..."
bash
curl -X POST https://api.infrai.cc/v1/cdn/distribution/create \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"origin": "..."}'

cdn.distribution.get

GET /v1/cdn/distribution/get/{distribution_id}

Fetch a CDN distribution's current state, edge hostname, and origin configuration.

Parameters

NameTypeRequiredDescription
distribution_idstring
Required
The distribution id.

Returns

Distribution

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at the console: Google/GitHub gives you
# $2 free credit (email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT,
# POST /v1/account/topup and open the returned checkout_url.
export INFRAI_API_KEY="ifr_pk_proj_..."
bash
curl -X GET https://api.infrai.cc/v1/cdn/distribution/get/DISTRIBUTION_ID \
  -H "Authorization: Bearer $INFRAI_API_KEY"

cdn.distribution.list

GET /v1/cdn/distribution/list

List all CDN distributions on the account.

Parameters

NameTypeRequiredDescription
cursorstringOptionalOpaque pagination cursor.
limitnumberOptionalMaximum number of items to return.

Returns

{ items: Distribution[], next_cursor?: string }

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at the console: Google/GitHub gives you
# $2 free credit (email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT,
# POST /v1/account/topup and open the returned checkout_url.
export INFRAI_API_KEY="ifr_pk_proj_..."
bash
curl -X GET https://api.infrai.cc/v1/cdn/distribution/list \
  -H "Authorization: Bearer $INFRAI_API_KEY"

cdn.distribution.update

PATCH /v1/cdn/distribution/update/{distribution_id}

Update a CDN distribution (enable/disable, origin, cache settings).

Parameters

NameTypeRequiredDescription
distribution_idstring
Required
The distribution id.
originstringOptionalOrigin host/URL the edge fronts.
domainstringOptionalPublic delivery hostname (CNAME target).
enabledbooleanOptionalWhether the distribution serves traffic.
cache_ttl_secondsnumberOptionalDefault edge cache TTL in seconds.
allowed_methodsstring[]OptionalHTTP methods the edge forwards.
https_onlybooleanOptionalForce HTTPS at the edge.
tagsstring[]OptionalCache-tag / surrogate-key labels.
vendorstringOptionalOptional explicit vendor pin; otherwise resolved by region.

Returns

Distribution

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at the console: Google/GitHub gives you
# $2 free credit (email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT,
# POST /v1/account/topup and open the returned checkout_url.
export INFRAI_API_KEY="ifr_pk_proj_..."
bash
curl -X PATCH https://api.infrai.cc/v1/cdn/distribution/update/DISTRIBUTION_ID \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"origin": "..."}'

cdn.distribution.delete

DELETE /v1/cdn/distribution/delete/{distribution_id}

Delete a CDN distribution and tear down its edge configuration.

Parameters

NameTypeRequiredDescription
distribution_idstring
Required
The distribution id.

Returns

{ ok: boolean }

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at the console: Google/GitHub gives you
# $2 free credit (email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT,
# POST /v1/account/topup and open the returned checkout_url.
export INFRAI_API_KEY="ifr_pk_proj_..."
bash
curl -X DELETE https://api.infrai.cc/v1/cdn/distribution/delete/DISTRIBUTION_ID \
  -H "Authorization: Bearer $INFRAI_API_KEY"

cdn.cache.purge

POST /v1/cdn/cache/purge

Purge the CDN edge cache for a distribution — by path, by cache-tag/surrogate-key, or everything. Billable work-action.

Parameters

NameTypeRequiredDescription
distribution_idstring
Required
The distribution id.
pathsstring[]OptionalSpecific URLs / path prefixes to purge.
tagsstring[]OptionalCache-tag / surrogate-key purge.
purge_everythingbooleanOptionalPurge the entire cache.
idempotency_keystringOptionalClient-supplied key to make the call idempotent.
vendorstringOptionalOptional explicit vendor pin; otherwise resolved by region.

Returns

{ ok: boolean, purge_id?: string }

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at the console: Google/GitHub gives you
# $2 free credit (email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT,
# POST /v1/account/topup and open the returned checkout_url.
export INFRAI_API_KEY="ifr_pk_proj_..."
bash
curl -X POST https://api.infrai.cc/v1/cdn/cache/purge \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"distribution_id": "..."}'

cdn.cache.stats

GET /v1/cdn/cache/stats

Read cache analytics for a distribution: requests, hit/miss, hit ratio, and bytes delivered (the metered egress that drives delivery billing).

Parameters

NameTypeRequiredDescription
distribution_idstringOptionalThe distribution id.
fromstringOptionalStart of the stats time range.
tostringOptionalEnd of the stats time range.

Returns

{ requests, bytes_served, hit_ratio }

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at the console: Google/GitHub gives you
# $2 free credit (email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT,
# POST /v1/account/topup and open the returned checkout_url.
export INFRAI_API_KEY="ifr_pk_proj_..."
bash
curl -X GET https://api.infrai.cc/v1/cdn/cache/stats \
  -H "Authorization: Bearer $INFRAI_API_KEY"
Advanced: pin a vendor

By default infrai routes each call to the best available provider — you do not pick a vendor. As an escape hatch, this capability accepts an optional vendor parameter to pin one specific provider. Every live vendor for this capability is available in real time from the discovery endpoint for the capability id — see the discovery API.

GET /v1/discovery/{capability}

cdn.distribution.create

cdn.distribution.update

cdn.cache.purge

All capabilities

Every routed capability in this module — the complete public REST contract. The methods above are the guided walkthrough; this index is the full reference.

CapabilityEndpointDescription
cdn.cache.purgePOST /v1/cdn/cache/purgePurge the CDN edge cache for a distribution — by path, by cache-tag/surrogate-key, or everything. Billable work-action.
cdn.cache.statsGET /v1/cdn/cache/statsRead cache analytics for a distribution: requests, hit/miss, hit ratio, and bytes delivered (the metered egress that drives delivery billing).
cdn.distribution.createPOST /v1/cdn/distribution/createCreate a CDN distribution (a vendor zone/service/domain) that fronts an origin with an edge cache, returning the CNAME target to point your hostname at.
cdn.distribution.deleteDELETE /v1/cdn/distribution/delete/{distribution_id}Delete a CDN distribution and tear down its edge configuration.
cdn.distribution.getGET /v1/cdn/distribution/get/{distribution_id}Fetch a CDN distribution's current state, edge hostname, and origin configuration.
cdn.distribution.listGET /v1/cdn/distribution/listList all CDN distributions on the account.
cdn.distribution.updatePATCH /v1/cdn/distribution/update/{distribution_id}Update a CDN distribution (enable/disable, origin, cache settings).

End-to-end example

A production-style walkthrough of this module: configure once, then run the flow. It exercises most of the module's APIs.

A copy-paste-runnable single-file Python program (stdlib only, no SDK): set your INFRAI_API_KEY, run it, and walk this module's core flow with REAL billed calls — later steps reuse real fields returned by earlier ones. The 12-line helper is the entire integration.

python
#!/usr/bin/env python3
"""Infrai · cdn — runnable real-app example (single file, zero deps).

Copy this file, set your key, run it: every step is a REAL call to
api.infrai.cc, billed at the real (tiny) per-call price, printing the
live JSON response. Get a key at https://console.infrai.cc (Google/
GitHub sign-in grants $2 free credit). No SDK — the 12-line helper
below is the entire integration."""
import json
import os
from urllib import error, request

KEY = os.environ.get("INFRAI_API_KEY") or "ifr_pk_proj_..."  # <- your key
BASE = "https://api.infrai.cc"


# Same raw HTTPS POST/GET as every per-method example on this page —
# wrapped once for reuse. There is nothing else to it: no SDK.
def infrai(method, path, body=None):
    req = request.Request(
        BASE + path, method=method,
        data=json.dumps(body).encode() if body is not None else None,
        headers={"Authorization": f"Bearer {KEY}",
                 "Content-Type": "application/json"})
    try:
        with request.urlopen(req, timeout=60) as r:
            return json.loads(r.read())
    except error.HTTPError as e:
        return json.loads(e.read())


def show(label, resp):
    print(f"\n== {label} ==")
    print(json.dumps(resp, indent=2, ensure_ascii=False))
    return resp


# 1) cdn.distribution.create — POST /v1/cdn/distribution/create · Create a CDN distribution (a vendor zone/service/domain) that fronts an origin with an edge cache, returning the CNAME target to point your hostname at.
r1 = show("cdn.distribution.create", infrai("POST", "/v1/cdn/distribution/create", {"origin":"..."}))

# 2) cdn.cache.purge — POST /v1/cdn/cache/purge · Purge the CDN edge cache for a distribution — by path, by cache-tag/surrogate-key, or everything. Billable work-action.
r2 = show("cdn.cache.purge", infrai("POST", "/v1/cdn/cache/purge", {"distribution_id":"..."}))

# 3) cdn.distribution.list — GET /v1/cdn/distribution/list · List all CDN distributions on the account.
r3 = show("cdn.distribution.list", infrai("GET", "/v1/cdn/distribution/list"))