DiceXDiceX/ Blog

API key security for messaging APIs: spending caps and IP restriction on DiceX keys

A leaked messaging API key costs real money. Here is how DiceX keys limit the damage: a spending cap per key, an IP allow list, one key per use, and what to do if a key leaks.

5 min read

API key security matters more for a messaging API than for most: a leaked key does not just expose data, it can send messages that are paid from your wallet. DiceX gives every API key two controls for that reason. A spending cap sets the maximum the key may spend through the API, and an IP restriction allows the key to be used only from the addresses you list. Combined with one key per use and keeping keys on the server, they keep a mistake or a leak small. This explainer shows how each control works in the DiceX developer panel and how to choose the settings.

Why API key security is different for SMS and WhatsApp

Most API keys guard data. A key for a sending API also guards money and reputation:

  • Cost. Every SMS, WhatsApp message or automated call sent with the key is paid from your wallet.
  • Reputation. Messages sent with your key go out from your sending lines, under your name.
  • Automation risk. A bug in a loop or a retry job can send the same message thousands of times before anyone notices. So can an AI agent given too much freedom. The goal is not only to keep the key secret, but to make sure that if something goes wrong, the damage has a ceiling.

The controls on a DiceX API key

You manage keys in the developer panel. When you create or edit a key, it has three sections:

Section

What you set

Worth knowing

Basic information

A descriptive title for the key

3 to 100 characters

Cost limit

Unlimited, or Limited with a maximum amount

The amount field appears only when you choose Limited

| Security and access | Allowed IPs, single or as ranges | An empty list allows every IP | After you submit, the DiceX team reviews the key, and it can be used once it is approved. Its status in the keys table shows whether it is pending review, approved or rejected. Creating a key may carry an activation fee; it is shown before you submit, and the key is not created until you accept it.

Spending cap

Under Cost limit, choose Limited. An amount field opens, and the value you enter is the maximum the key may spend through the API. A minimum amount applies, and the panel shows it. How to choose the number:

  • Estimate what the key needs for a normal period, such as a day or a campaign, and add a margin.
  • Give background jobs and AI agents tighter caps than your main backend. They are the ones most likely to run away.
  • Revisit the cap when your volume grows, instead of switching to unlimited. A cap does not replace monitoring, but it turns «we sent everything in the wallet» into «we hit the cap and noticed».

IP restriction

Under Security and access, choose the restriction type:

  • Single IP: allow one or more specific addresses, such as your production server.
  • IP range: allow a range with a start and an end address. The small globe button accepts a CIDR such as 10.0.0.0/24 and turns it into the start and end addresses for you. You can add several addresses or ranges; all of them are allowed. If the list stays empty, the key works from every IP. For any key used by a server with a fixed address, fill it in.

One key per use

A single key shared by every app is convenient until you need to change it. A key per use gives you:

  • Separate caps. Your checkout backend, your marketing jobs and your AI agent each get a limit that fits them.
  • Separate IP lists. Staging and production run on different machines, so they get different allowed addresses.
  • Clean revocation. If one key leaks, you delete that key; the others keep working.
  • Clear titles. Name keys after their use, such as «production backend» or «support agent», so the table tells you at a glance what each one is for.

Keeping the key secret

Controls on the key limit the damage. These habits avoid it:

  • Server side only. Call the API from your backend. Never put a key in a mobile app, browser code or a public repository.
  • Environment variables. Read the key from the environment, as the DiceX samples do with DICEX_API_KEY, instead of writing it in code.
  • Header, not URL. Send the key in the ApiKey header. SendSingleSMS also has a GET version that takes the key as a query parameter; prefer POST, because URLs end up in logs and histories.
  • Not in prompts. If an AI agent uses the API, connect it through MCP or a server-side tool, and keep the key out of chat text.
  • Do not share it. A key is not a password to pass between colleagues; create a new key instead.

If a key leaks

The DiceX panel's own advice is direct: if a key is exposed, delete it immediately and create a new one. In practice:

  1. Delete the exposed key in the developer panel. Deletion cannot be undone.
  2. Create a replacement with the same title, cap and IP list. It will go through review again, and an activation fee may apply.
  3. Update the key in your server's environment and restart the service.
  4. Check your sent messages and wallet for anything you did not send.

A quick checklist

  • [ ] Every key has a title that says what it is for
  • [ ] Every automated key has a spending cap
  • [ ] Every server-side key has an IP restriction
  • [ ] Keys live in environment variables, not in code
  • [ ] Requests send the key in the ApiKey header
  • [ ] You know how to delete and replace a key Related reading: the overview of the DiceX communications API and how to give an AI agent its own key through the MCP server for SMS and WhatsApp.

Next step

Open the developer panel, review each key's cost limit and allowed IPs, and split shared keys into one per use. For the rest of the API, see the developers hub and the API reference; for using keys with AI agents, see the AI hub.

Frequently asked questions

Can I limit how much a DiceX API key can spend?

Yes. When you create or edit a key in the developer panel, choose a limited cost and enter the maximum amount the key may spend through the API.

Can I restrict a key to my server's IP address?

Yes. Add single IP addresses or ranges to the key's allowed list; a CIDR such as 10.0.0.0/24 can be turned into a start and end address. If the list is empty, every IP is allowed.

What should I do if my API key leaks?

Delete the key immediately in the developer panel and create a new one, then update your server with the new key.

Is one key enough for all my apps?

It works, but one key per use is safer: each key gets its own cap and IP list, and deleting one does not stop the others.

For developers

Related articles