Skip to content

How to Choose a TLS Certificate for an API With Many Hostnames

APIs often serve many hostnames across regions, tenants and versions. Learn how to compare single, SAN and wildcard certificates and plan rotation for API clients.

10 min readUpdated Nov 21, 2026By XPASS Editorial Team

How to Choose a TLS Certificate for an API With Many Hostnames

A single website has a simple TLS story: one hostname, one certificate. An API platform rarely does. You might serve api.example.com for the current version, api-v2.example.com for a beta, regional endpoints such as eu.api.example.com, webhook receivers, an internal service mesh, sandbox environments for customers, and per-customer subdomains if you run a multi-tenant product. Each of those names is contacted by software that cannot click through a warning page. When a certificate is wrong, the result is not an ugly screen; it is a failed request in someone else's production system.

This guide helps you choose a certificate approach for such an API. It compares single-name, SAN and wildcard certificates, covers things specific to API clients such as trust stores, pinning and mutual TLS, and describes a rollout and rotation plan that keeps integrations running.

What makes API certificates different

Browsers are forgiving in ways that API clients are not. A person can read an error and decide what to do. A script, mobile app, IoT device or partner system either connects or fails, usually with a terse message in a log that nobody reads until customers complain. This changes how you think about certificates in four ways.

  • Strict validation. Libraries commonly check the certificate chain, the host name and the validity dates, and refuse to continue on any problem. They often do not fetch missing intermediate certificates the way a desktop browser might, so an incomplete chain can break clients that a browser test would not reveal.
  • Different trust stores. Not every client uses the operating system's trusted roots. Some bundle their own list, some run on old devices that never receive updates, and some use a private store. A certificate from a widely trusted issuer is usually safer for public clients, but you cannot assume every device trusts it.
  • Long-lived deployments. Mobile apps and devices in the field may live for years. Choices you make now, such as pinning, stay with those installs.
  • Hidden callers. You may not know every system that calls your API. A change that looks safe internally can break a partner integration.

The underlying protocol is TLS, specified in documents such as RFC 8446 for version 1.3. The certificate format is the X.509 profile in RFC 5280. Your certificate choice sits on top of that, and decides which names a client will accept.

The three certificate shapes for many hostnames

For a multi-host API, the main question is how the certificate lists its names.

Type How names are listed Good for Watch out for
Single-name One exact hostname A few sensitive endpoints, such as payment or admin APIs Many certificates to track and renew
SAN (multi-name) An explicit list of hostnames, possibly across domains A known, stable set of endpoints Adding a name means reissuing and redeploying
Wildcard One label, such as *.api.example.com Many subdomains created often, such as tenants or regions Does not cover the bare name or deeper levels; a leaked key affects all matching hosts

Often the best answer is a mixture. For example, use a SAN certificate for a fixed set of public endpoints (api, api-v2, webhooks), a wildcard for customer or tenant subdomains, and a separate single-name certificate for the authentication endpoint if you want it isolated. The article on whether a new subdomain needs a new wildcard certificate explains exactly what a wildcard matches and where it stops, which is essential when you design tenant naming.

Step 1: list the hostnames and who calls them

Before choosing, write down every hostname your API answers on, for now and for the next year. A table is enough:

Hostname Purpose Callers Created how
api.example.com Production API Public clients, SDKs Fixed
api-v2.example.com Beta version Selected partners Fixed
webhooks.example.com Inbound events Payment and CRM providers Fixed
tenant1.api.example.com Per-customer endpoints Customer systems Automatically on sign-up
sandbox.example.com Test environment Developers Fixed

The last column matters most. Names that are fixed fit a SAN certificate. Names created automatically in large numbers, for example one per customer, fit a wildcard or a dynamic certificate system. If you are unsure how many hostnames you actually have, start with the inventory approach described in the guide to managing SSL across many company domains.

Step 2: decide on isolation and blast radius

Ask what happens if the private key for a certificate leaks or you must replace it urgently. With one shared certificate across all API hostnames, a leak means replacing the certificate everywhere at once and revoking the old one, while clients may be mid-request. With separate certificates per tier, you replace only the affected tier.

A practical split looks like this:

  1. Public production API. A SAN or single-name certificate with a key stored only on the servers or load balancers that terminate TLS.
  2. Tenant and customer subdomains. A wildcard, with the key held in one controlled place such as a load balancer or secrets manager rather than copied to each application host.
  3. Sandbox and staging. A separate certificate and a separate key from production. Do not reuse the production key in a less protected environment.
  4. Internal service-to-service traffic. Often better served by a private certificate authority than a public certificate, because you control the clients and the trust list, and you can issue short-lived certificates automatically.

Terminating TLS at a shared edge, such as a load balancer or gateway, reduces the number of places the key lives. If you terminate in many services, be deliberate about who can read the key files.

Step 3: consider client behaviour

Before you commit, test what your clients do. A few topics to cover:

  • Full chain. Serve the leaf certificate and the intermediates supplied by your issuer. Test with the lowest-capability client you support, not only a modern browser.
  • Name matching. Clients match the hostname they connect to against the certificate names. Make sure the exact hostnames used in SDK defaults, documentation and customer configuration are all covered.
  • Certificate pinning. If some clients pin a certificate or public key, rotation can break them. If you must support pinning, prefer pinning to a key or an intermediate you control and publish a rotation procedure. Avoid pinning in new designs unless you have a clear need and a way to update clients.
  • SNI. Serving many hostnames from one IP address relies on Server Name Indication so the server can choose the right certificate. Very old clients without SNI support may receive a default certificate, so check if any exist among your callers.
  • Protocol versions. Allow modern TLS versions and disable ones your security policy rules out. Check that your oldest supported client can still connect.

Mutual TLS

Some APIs require clients to present their own certificate, known as mutual TLS. This is separate from the server certificate you are choosing. For mutual TLS, you typically issue client certificates from a private authority, define how they are provisioned and revoked, and decide how the server verifies them. Do not mix this up with the public server certificate: the server certificate proves your hostname to the client, while the client certificate proves the client to you.

Step 4: plan issuance and rotation

An API that runs continuously needs rotation that does not drop requests. A reliable approach:

  1. Automate issuance where you can. The ACME protocol in RFC 8555 lets software prove control of names and obtain certificates automatically. Wildcard names normally require a DNS-based challenge, so decide how the automation will be allowed to change DNS, and keep its permissions narrow.
  2. Renew early. Set renewal to start well before expiry so that failures have time to be noticed and fixed.
  3. Deploy in stages. Replace the certificate on a small share of servers first, watch client error rates, and then continue. Load balancers that support multiple certificates make it easier to switch gradually.
  4. Keep a rollback. Hold on to the previous certificate and key until you are sure the new one works for all callers.
  5. Monitor from the outside. Check the certificate that each public hostname actually serves, from more than one network, and alert on remaining validity.
  6. Tell integrators. If you publish a pinning or trust requirement, announce any planned change early through your developer channels.

If your API sits next to a content site, such as a WordPress blog or documentation portal on the same domain, remember that site needs a certificate too. The guide on installing SSL on WordPress covers that part, and it is worth deciding whether the site shares a certificate with the API or has its own.

A plain example

Consider a company that runs a payments API. It has api.example.com, api-sandbox.example.com, webhooks.example.com and, for each customer, a dashboard at customer1.example.com.

The team decides on three certificates. A SAN certificate covers the three fixed names (api, api-sandbox, webhooks) and is held on the edge load balancer. A separate wildcard *.example.com serves customer dashboards, with its key held only on the dashboard cluster. They keep the sandbox on a different certificate and key from production by requesting the sandbox name separately, so a mistake in testing cannot expose the production key.

Before the first rotation, they test with the oldest SDK version, an Android client and a partner's server library. One partner library fails because the server sent only the leaf certificate, not the intermediate. They fix the chain on the load balancer, and the next rotation goes ahead in stages with no support tickets.

Limits and what to watch for

  • A certificate does not secure the API. It encrypts the connection and proves the hostname. Authentication, authorisation, input validation and rate limiting are separate controls.
  • Wildcards are broad. Anything under the wildcard can be served with the same trusted certificate, including hosts created later. Control who can create DNS records and who can read the key.
  • Validity periods change. Public certificate lifetimes are set by industry rules published by bodies such as the CA/Browser Forum and have trended shorter. Design for frequent renewal, not for a certificate that lasts years.
  • Customer-owned domains. If customers use their own domain names to reach your API, you need a way to obtain and renew certificates for those names, often by an automated process that verifies the customer controls the domain. That is a different design from a wildcard on your own domain.
  • Revocation is imperfect. Not all clients check revocation reliably, so short lifetimes and quick replacement are the more dependable protections.
  • Private keys. Generate them on the machine or service that will use them where possible, restrict file permissions, and avoid sending them through chat or tickets.

Summary

Choosing a TLS certificate for an API with many hostnames starts with listing every name, how each is created and who calls it. Use SAN certificates for a fixed set of public endpoints, wildcards for names created automatically under one domain, and single-name certificates when you want isolation for a sensitive endpoint. Limit the blast radius by separating production, sandbox and tenant keys, and keep keys in as few controlled places as possible. Test with the least capable client you support, serve the full chain, avoid pinning unless you can manage it, and plan staged, monitored rotation with automation where possible.

When you are ready to compare certificate types for your hostnames, you can review the options on the SSL page.

Frequently asked questions

Which certificate type suits an API with many hostnames?

It depends on how names are created. A SAN certificate suits a fixed, known list of hostnames. A wildcard suits many single-label subdomains under one domain. Single-name certificates suit a few sensitive endpoints that you want to isolate.

Do API clients validate certificates differently from browsers?

Many do the same checks, but some use their own trust stores, may not tolerate missing intermediate certificates and may pin a certificate or key. Test with the actual client libraries you support before rotating.

Can one certificate cover tenant subdomains like tenant1.api.example.com?

A wildcard such as *.api.example.com matches one label under api.example.com. It does not cover deeper names, and it does not cover api.example.com itself unless that name is listed too.

How should certificates be rotated for an API?

Renew well ahead of expiry, deploy to a small subset first, watch client error rates, and then roll out gradually. Automate with ACME where possible, and keep a rollback path in case clients reject the new certificate.

About the author

Bob Kanokphon Thongdee, founder of XPASS VPN

Bob Kanokphon Thongdee

  • Founder of XPASS VPN
  • Co-founder of eSIMonline.asia
  • More than 7 years in online marketing
  • Founder of Cojourney Visa and Cojourney Travel

Need an SSL certificate?

Pick the certificate type that fits your site and see the price before you check out.

SSL from $14.99

See SSL certificates

Keep reading

SSL Guides

Does a New Subdomain Need a New Wildcard SSL Certificate?

A wildcard certificate covers many subdomains, but not all of them. Learn what it includes, which names need a new certificate, and how to add a subdomain safely.

9 min read

SSL Guides

How to Install SSL on a WordPress Website

A practical walkthrough for moving WordPress to HTTPS: installing the certificate, updating URLs, fixing mixed content, redirecting and checking the result.

10 min read

SSL Guides

How to Manage SSL Certificates Across Many Company Domains

Once a company owns many domains, SSL stops being a one-off task. Learn how to inventory certificates, pick the right types, assign owners and renew without outages.

10 min read