RelayAPI

Python REST and OpenAPI

Call RelayAPI safely from Python over REST or generate a private client from the maintained OpenAPI contract.

RelayAPI does not currently publish an official Python package. Use the REST API directly with your preferred HTTP library, or generate and review a private Python client from the maintained OpenAPI document.

Do not install the unrelated PyPI project named relay. It is not a RelayAPI SDK. The canonical hosted contract is https://api.relayapi.dev/openapi.json.

Authentication

Set the API key in your environment:

export RELAY_API_KEY="rlay_live_your_api_key"

The following helper uses only Python's standard library:

import json
import os
from urllib.error import HTTPError
from urllib.request import Request, urlopen

BASE_URL = os.getenv("RELAY_BASE_URL", "https://api.relayapi.dev").rstrip("/")
API_KEY = os.environ["RELAY_API_KEY"]


def relay_request(method, path, payload=None):
    body = None if payload is None else json.dumps(payload).encode("utf-8")
    request = Request(
        f"{BASE_URL}{path}",
        data=body,
        method=method,
        headers={
            "Authorization": f"Bearer {API_KEY}",
            "Accept": "application/json",
            **({"Content-Type": "application/json"} if body is not None else {}),
        },
    )
    try:
        with urlopen(request, timeout=60) as response:
            return json.load(response)
    except HTTPError as error:
        detail = error.read().decode("utf-8", errors="replace")
        raise RuntimeError(f"RelayAPI returned HTTP {error.code}: {detail}") from error

Create and publish a post

post = relay_request(
    "POST",
    "/v1/posts",
    {
        "content": "Hello from Python over REST!",
        "targets": ["twitter", "linkedin"],
        "scheduled_at": "now",
    },
)

print(post["id"], post["status"])

For retried mutations, send one stable Idempotency-Key header for the logical operation. Extend the helper with an optional header argument when your application retries requests.

Start an OAuth connection

flow = relay_request("GET", "/v1/connect/twitter")
print(flow["auth_url"])

Redirect the user to auth_url. The returned state is one-time and bound to the initiating credential and dashboard session when applicable.

List connected accounts

page = relay_request("GET", "/v1/accounts?limit=20")

for account in page["data"]:
    print(account["platform"], account.get("display_name"), account["id"])

while page["has_more"]:
    cursor = page["next_cursor"]
    page = relay_request("GET", f"/v1/accounts?limit=20&cursor={cursor}")

Use urllib.parse.urlencode when query values can contain characters that require escaping.

Generate a private Python client

The complete OpenAPI 3.1 contract is available at:

You can feed that document to OpenAPI Generator or another generator you control. Pin the contract revision, review the generated authentication, retries, pagination, streaming, and idempotency behavior, and publish the result only under a package name owned by your organization.

@relayapi/sdk is the canonical current client maintained with this repository. A generated Python client can lag unless you regenerate it from the current contract.

Found something wrong? Help us improve this page.

On this page