# invalid_idempotency_key

- HTTP status: 400
- Retry: No
- Execution: not started
- Admin needed: no

**Invalid Idempotency-Key.** The `Idempotency-Key` header was present but empty, too long, or contained spaces or non-ASCII characters.

## What it means

The API returns HTTP 400 with `error.code` set to `invalid_idempotency_key`. The default message is: "The Idempotency-Key header must be 1 to 255 printable ASCII characters with no spaces."

## Common causes

- A key longer than 255 characters.
- A key containing spaces, tabs or non-ASCII characters.

## How to identify it

Check the response status (`400`) and `error.code` (`invalid_idempotency_key`). Branch on `error.code`, not on the message text: messages can be reworded, codes do not change within v1. Log `error.request_id` (also sent as the `X-Request-Id` header) so support can find the request.

## How to fix it

- Use a UUID v4 or another URL-safe token of at most 255 characters.

## Retry guidance

Sending the request unchanged fails the same way. Fix the cause first (see How to fix it), then send it again.

## Did anything happen?

This request was refused before any call was placed and before anything was charged.

## Idempotency

Send a valid key. Nothing was done.

## Who can fix it

The developer who sends the request can fix it; no administrator action is normally needed.

## When to contact support

If the error persists after the steps above, contact [support@relationsai.com](mailto:support@relationsai.com). See [Support](/resources/support) for what to include (the `request_id`, the time in UTC, the operation, and whether you used a test or live key) and what never to send (API keys, Authorization headers, webhook signing secrets, recording links, transcripts or customer data).

## Example error response

```json
{
  "error": {
    "code": "invalid_idempotency_key",
    "message": "The Idempotency-Key header must be 1 to 255 printable ASCII characters with no spaces.",
    "details": {},
    "request_id": "req_oow7drypdti4zyumdehx6iuz",
    "retry": "no",
    "doc_url": "https://docs.relationsai.com/errors/invalid_idempotency_key"
  }
}
```

## Incorrect and corrected request

Incorrect: The key contains spaces.

```http
POST /v1/calls
Authorization: Bearer rai_test_YOUR_TEST_KEY
Content-Type: application/json
Idempotency-Key: call Asha retry 1

{
  "agent_id": "agent_4Nf8Gt2Hx6Jq9Lm3Pv7Rs1",
  "to": "+12025550100"
}
```

Corrected: A UUID v4: printable ASCII, no spaces, at most 255 characters.

```http
POST /v1/calls
Authorization: Bearer rai_test_YOUR_TEST_KEY
Content-Type: application/json
Idempotency-Key: 6f1d2c84-5b7e-4a3f-9c2d-8e1b0a7f4d63

{
  "agent_id": "agent_4Nf8Gt2Hx6Jq9Lm3Pv7Rs1",
  "to": "+12025550100"
}
```

## Operations that can return this error

- [`POST /calls`](/api/calls#place-a-call): Place a call
- [`POST /campaigns`](/api/campaigns#create-a-campaign): Create a campaign
- [`POST /campaigns/{campaign_id}/recipients`](/api/campaigns#add-recipients): Add recipients
- [`POST /campaigns/{campaign_id}/start`](/api/campaigns#start-a-campaign): Start a campaign
- [`POST /campaigns/{campaign_id}/pause`](/api/campaigns#pause-a-campaign): Pause a campaign
- [`POST /campaigns/{campaign_id}/resume`](/api/campaigns#resume-a-campaign): Resume a campaign
- [`POST /campaigns/{campaign_id}/stop`](/api/campaigns#stop-a-campaign): Stop a campaign
- [`POST /contacts`](/api/contacts#create-a-contact): Create a contact
- [`POST /contacts/upsert`](/api/contacts#create-or-update-a-contact-by-phone-number): Create or update a contact by phone number
- [`DELETE /contacts/{contact_id}`](/api/contacts#delete-a-contact): Delete a contact
- [`POST /dnc-entries`](/api/do-not-call-list#add-a-number-to-the-do-not-call-list): Add a number to the do-not-call list
- [`DELETE /dnc-entries/{dnc_entry_id}`](/api/do-not-call-list#remove-a-number-from-the-do-not-call-list): Remove a number from the do-not-call list
- [`POST /webhook-endpoints`](/api/webhook-endpoints#create-a-webhook-endpoint): Create a webhook endpoint
- [`DELETE /webhook-endpoints/{webhook_endpoint_id}`](/api/webhook-endpoints#delete-a-webhook-endpoint): Delete a webhook endpoint
- [`POST /webhook-endpoints/{webhook_endpoint_id}/rotate-secret`](/api/webhook-endpoints#rotate-a-webhook-signing-secret): Rotate a webhook signing secret
- [`POST /webhook-endpoints/{webhook_endpoint_id}/test`](/api/webhook-endpoints#send-a-test-event): Send a test event
- [`POST /webhook-deliveries/{webhook_delivery_id}/retry`](/api/webhook-endpoints#retry-a-delivery): Retry a delivery

See all codes in the [error-code reference](/fundamentals/error-codes).
