Skip to content
Pidgely Docs

Get started

Authentication

Authenticate with API keys sent as Bearer tokens. Choose full_access or sending_access, restrict sending keys to a single domain and limit any key to the IP addresses of your servers.

View as Markdown

Every request to the API carries an API key in the Authorization header:

HTTP
POST /emails HTTP/1.1
Host: api.pidgely.com
Authorization: Bearer pdg_k3x7m2qa4bnp6c5d_xyy4u7c2r3w5t6v7m8n9p2q3r4s5t6u7
Content-Type: application/json

The scheme must be exactly Bearer (capital B, one space). A request without it gets 401 missing_api_key; an unknown or revoked key gets 403 invalid_api_key; a key used from an address outside its IP allowlist gets 403 ip_not_allowed.

Key format

Keys look like pdg_<prefix>_<secret>: a public prefix that identifies the key and a secret part. Pidgely stores only an HMAC of the secret, so the full key is shown once, when you create it. If you lose it, create a new key and revoke the old one.

Permissions

Permission Can call Use it for
full_access (default) Every endpoint Back-office scripts, infrastructure as code, the MCP server when you trust the agent
sending_access POST /emails, POST /emails/batch and GET /emails/{id} only Application servers that only send

A sending_access key that calls any other endpoint gets:

JSON
{
  "statusCode": 401,
  "name": "restricted_api_key",
  "message": "This API key is restricted to only send emails."
}

The same applies to SMTP: any valid key can submit mail there.

Domain-restricted keys

Pass domain_id when you create a key to restrict it to one verified domain. Such a key is always sending_access, and sending from any other domain fails with 403 validation_error (this API key cannot send from <domain>).

Node.js
import { Pidgely } from 'pidgely';

const pidgely = new Pidgely(process.env.PIDGELY_API_KEY);

const { data, error } = await pidgely.apiKeys.create({
  name: 'Web app (acme.com)',
  permission: 'sending_access',
  domainId: '0199d7f0-1c2b-7e4d-a5f6-0b9c8d7e6f51',
});
console.log(data ?? error);
Python
import os
import pidgely

pidgely.api_key = os.environ["PIDGELY_API_KEY"]

result = pidgely.ApiKeys.create({
    "name": "Web app (acme.com)",
    "permission": "sending_access",
    "domain_id": "0199d7f0-1c2b-7e4d-a5f6-0b9c8d7e6f51",
})
print(result)
PHP
<?php

require __DIR__ . '/vendor/autoload.php';

$pidgely = Pidgely::client(getenv('PIDGELY_API_KEY'));

$result = $pidgely->apiKeys->create([
    'name' => 'Web app (acme.com)',
    'permission' => 'sending_access',
    'domain_id' => '0199d7f0-1c2b-7e4d-a5f6-0b9c8d7e6f51',
]);
var_dump($result);
Go
package main

import (
	"context"
	"fmt"
	"os"

	"github.com/pidgely/pidgely-go"
)

func main() {
	ctx := context.Background()
	client := pidgely.NewClient(os.Getenv("PIDGELY_API_KEY"))

	result, err := client.ApiKeys.Create(ctx, &pidgely.CreateApiKeyRequest{
		Name:       "Web app (acme.com)",
		Permission: "sending_access",
		DomainId:   "0199d7f0-1c2b-7e4d-a5f6-0b9c8d7e6f51",
	})
	if err != nil {
		panic(err)
	}
	fmt.Println(result)
}
Ruby
require "pidgely"

Pidgely.api_key = ENV["PIDGELY_API_KEY"]

result = Pidgely::ApiKeys.create({
  name: "Web app (acme.com)",
  permission: "sending_access",
  domain_id: "0199d7f0-1c2b-7e4d-a5f6-0b9c8d7e6f51"
})
puts result
cURL
curl -X POST 'https://api.pidgely.com/api-keys' \
  -H "Authorization: Bearer $PIDGELY_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "name": "Web app (acme.com)",
  "permission": "sending_access",
  "domain_id": "0199d7f0-1c2b-7e4d-a5f6-0b9c8d7e6f51"
}'

Give each service its own restricted key: a leaked key can then only send from one domain and can't read your contacts, change DNS settings or create new keys.

IP restrictions

Any key, full_access or sending_access, can be limited to the addresses of your servers. Pass allowed_ips when you create the key, or change it later with Update API key or from the key's menu in the dashboard:

Shell
curl -X POST https://api.pidgely.com/api-keys \
  -H "Authorization: Bearer $PIDGELY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Production (eu-west)",
    "permission": "sending_access",
    "allowed_ips": ["203.0.113.7", "198.51.100.0/24", "2001:db8:4f2::/48"]
  }'

To change the list later, send only allowed_ips:

Shell
curl -X PATCH https://api.pidgely.com/api-keys/0199d7f0-1c2b-7e4d-a5f6-0b9c8d7e6f52 \
  -H "Authorization: Bearer $PIDGELY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"allowed_ips": ["203.0.113.7", "203.0.113.8"]}'
  • Entries are IPv4 or IPv6 addresses (203.0.113.7) or CIDR networks (198.51.100.0/24), up to 50 per key. Pidgely normalises them: a network is stored by its first address (10.1.2.3/8 becomes 10.0.0.0/8) and an IPv4-mapped IPv6 address (::ffff:203.0.113.7) becomes plain IPv4. An invalid entry fails with 422 validation_error on the field allowed_ips.
  • An empty list (the default) accepts any address. PATCH /api-keys/{id} with "allowed_ips": [] lifts the restriction; allowed_ips always replaces the whole list.
  • The check covers the REST API and SMTP, where the key is the password. Over HTTP, Pidgely uses the address that connected to its edge (headers your client sets, such as X-Forwarded-For, can't spoof it). Over SMTP, it is the address of the TCP connection.
  • Changes apply within about 30 seconds, the same delay as revocation.

A request from any other address is refused before anything else runs, and the message names the address Pidgely saw, so you know what to add:

JSON
{
  "statusCode": 403,
  "name": "ip_not_allowed",
  "message": "this API key cannot be used from IP 192.0.2.66: add it to the key's allowed IPs"
}

The native /v1 API answers 403 with {"error": {"code": "ip_not_allowed", ...}}, and SMTP rejects the login with 535 5.7.1 and the same message.

When you create a key in the dashboard, Restrict by IP offers your current address with one click (Use my IP). That is the address of the computer running your browser: use it for keys you call from that machine, and add your servers' outbound addresses for production keys. Servers behind NAT, a cloud egress gateway or serverless platforms often go out through a range of addresses; list the provider's published range, or use a fixed egress IP.

Keep keys on the server

The API does not answer CORS requests, so it can't be called from a browser, and it shouldn't be: anyone could read a key embedded in front-end code. Call Pidgely from your backend, a serverless function or a job runner, and load the key from an environment variable or a secret manager.

Rotating and revoking keys

  1. Create a new key and deploy it.
  2. Delete the old key.

Revocation takes effect within about 30 seconds, as authentication results are cached briefly. GET /api-keys shows last_used_at for each key, which helps to spot keys that are no longer used.

Accounts and limits

All keys of an account share the same rate limit and quotas, suppression list, domains and contacts. New accounts start in a sandbox on the Free plan; see Rate limits & quotas for what that means.

People sign in to the dashboard with their e-mail and password or with Continue with Google / Continue with GitHub, which use the address the provider has verified. Linked accounts, a password for accounts created with Google or GitHub, and two-factor authentication are managed in Settings → Security. How someone signs in to the dashboard never changes API keys: they keep working until they are revoked.