# Add a custom domain

<div class="api-op" data-api-operation>
<div class="api-op__main">

<p class="api-note">DNS records returned.</p>

<p class="api-endpoint"><span class="method method-post">POST</span> <code>/v1/custom_domains</code></p>

Email sender domains are bounded to 100 per environment. Portal hostnames (Pro plans and above), broker, SCIM and combined `broker_scim` hostnames (Business plans and above; at most 100 hostnames per environment, a plan that does not allow the type answers `plan_limit_reached`) are registered with Cloudflare for SaaS with our origin-pull certificate attached; the response lists the CNAME to publish and the ownership and certificate TXT records Cloudflare returned. The hostname stays `pending` until both the hostname and its certificate are active, and serves traffic only for connections of its own environment. A hostname the provider refuses answers `parameter_invalid`; a hostname already registered answers `resource_already_exists`. There is no platform-wide limit on `signin` hostnames. Once one is verified and made the environment's active sign-in host (`PUT /v1/environment/signin_host`), new end-user passkeys bind to it as their own WebAuthn relying party (`signin_hostname_limit_reached` is no longer returned).

<dl class="api-facts"><div><dt>Scope</dt><dd><code>custom_domains:write</code></dd></div><div><dt>Auth</dt><dd>Secret key (<code>sk_…</code>)</dd></div><div><dt>Since</dt><dd>1.0</dd></div></dl>

## Headers

<ul class="api-fields">
<li class="api-field">
<p class="api-field__head"><code class="api-field__name">OhAuthCat-Version</code> <span class="api-field__type">string</span></p>
Minor version; defaults to the environment's pin.
</li>
<li class="api-field">
<p class="api-field__head"><code class="api-field__name">Idempotency-Key</code> <span class="api-field__type">string</span></p>
Honoured for 24 h; a replay returns the original response.

<p class="api-field__chips">min length 1 · max length 255</p>
</li>
</ul>

## Request body

<ul class="api-fields">
<li class="api-field">
<p class="api-field__head"><code class="api-field__name">type</code> <span class="api-field__type">string</span> <span class="api-field__required">Required</span></p>
`signin` (Pro and above) serves the environment's hosted sign-in app on the hostname; once verified it is accepted as a sign-in API (CORS) and passkey origin for that environment only. `broker_scim` (Business and above) serves sign-in and SCIM on one hostname, as a vendor that did both on one host (a self-hosted Polis) did: paths under `/scim/` and the legacy SCIM base paths of imported directories reach SCIM only, every other path reaches sign-in only.

<p class="api-field__chips">one of <code>portal</code>, <code>broker</code>, <code>scim</code>, <code>email</code>, <code>signin</code>, <code>broker_scim</code></p>
</li>
<li class="api-field">
<p class="api-field__head"><code class="api-field__name">hostname</code> <span class="api-field__type">string</span> <span class="api-field__required">Required</span></p>

<p class="api-field__chips">min length 1 · max length 253</p>
</li>
<li class="api-field">
<p class="api-field__head"><code class="api-field__name">spf_record</code> <span class="api-field__type">string</span></p>
Email only. Exact SPF TXT configuration to verify at the sender domain.

<p class="api-field__chips">min length 1 · max length 1024</p>
</li>
<li class="api-field">
<p class="api-field__head"><code class="api-field__name">dkim_records</code> <span class="api-field__type">array of DnsRecord</span></p>
Email only. Exact DKIM TXT or CNAME configuration records.

<p class="api-field__chips">min items 1 · max items 3</p>
</li>
</ul>

## Responses

<ul class="api-responses">
<li class="api-response"><span class="api-status api-status--ok">201</span> <span>OK <span class="api-field__type">CustomDomain</span></span></li>
<li class="api-response"><span class="api-status api-status--bad">400</span> <span>Invalid request. Codes: <a href="/errors/parameter_invalid/">parameter_invalid</a>, <a href="/errors/parameter_missing/">parameter_missing</a>, <a href="/errors/version_unsupported/">version_unsupported</a> and resource-specific codes from the catalogue. <span class="api-field__type">Error</span></span></li>
<li class="api-response"><span class="api-status api-status--bad">401</span> <span>Codes: <a href="/errors/authentication_required/">authentication_required</a>, <a href="/errors/api_key_invalid/">api_key_invalid</a>. <span class="api-field__type">Error</span></span></li>
<li class="api-response"><span class="api-status api-status--bad">403</span> <span>Codes: <a href="/errors/api_key_scope_missing/">api_key_scope_missing</a>, <a href="/errors/ip_not_allowed/">ip_not_allowed</a>, <a href="/errors/plan_limit_reached/">plan_limit_reached</a>. <span class="api-field__type">Error</span></span></li>
<li class="api-response"><span class="api-status api-status--bad">409</span> <span>Codes: <a href="/errors/idempotency_key_reused/">idempotency_key_reused</a> and resource-specific conflicts. <span class="api-field__type">Error</span></span></li>
<li class="api-response"><span class="api-status api-status--bad">429</span> <span>Code: <a href="/errors/rate_limited/">rate_limited</a>. Retry-After is set. <span class="api-field__type">Error</span></span></li>
<li class="api-response"><span class="api-status api-status--bad">503</span> <span>Code: <a href="/errors/service_unavailable/">service_unavailable</a>. Retry-After is set; writes are paused. <span class="api-field__type">Error</span></span></li>
<li class="api-response"><span class="api-status api-status--neutral">default</span> <span>Any other error, including <a href="/errors/internal_error/">internal_error</a>. Every code is in the error catalogue. <span class="api-field__type">Error</span></span></li>
</ul>

Errors share one shape; see the [error code catalogue](/errors/).

</div>
<div class="api-op__code">

**curl**

```sh wrap
curl -X POST \
  "https://api.ohauthcat.com/v1/custom_domains" \
  -H "Authorization: Bearer $OHAUTHCAT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "type": "portal",
  "hostname": "acme.com"
}'
```

**Node**

```javascript wrap
const response = await fetch("https://api.ohauthcat.com/v1/custom_domains", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.OHAUTHCAT_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    type: "portal",
    hostname: "acme.com",
  }),
});
const data = await response.json();
```

**Python**

```python wrap
import os
import requests

response = requests.post(
    "https://api.ohauthcat.com/v1/custom_domains",
    headers={"Authorization": f"Bearer {os.environ['OHAUTHCAT_API_KEY']}"},
    json={
        "type": "portal",
        "hostname": "acme.com",
    },
)
data = response.json()
```

```json title="Response 201" wrap
{
  "id": "cdom_01J9Z3K5V7W8X9Y0Z1A2B3C4D5",
  "object": "custom_domain",
  "type": "portal",
  "hostname": "acme.com",
  "state": "pending",
  "dns_records": [
    {
      "type": "CNAME",
      "name": "Acme Corp",
      "value": "enterprise"
    }
  ],
  "created_at": "2026-01-15T09:30:00Z"
}
```

</div>
</div>
