> For the complete documentation index, see [llms.txt](https://docs.pay.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pay.io/api-reference/merchant-console-api/refresh-api-key.md).

# Refresh API Key

## Refresh API key with grace period

> Refreshes a merchant's API key, generating a new key while keeping the old key valid during a grace period. This allows merchants to rotate their API keys seamlessly without service interruption. Both keys will work during the grace period.

```json
{"openapi":"3.0.0","info":{"title":"pay.io payment gateway","version":"1.0"},"servers":[{"url":"https://gateway.stage.pay.io","variables":{}}],"paths":{"/v1/merchant/api_key/refresh":{"post":{"callbacks":{},"description":"Refreshes a merchant's API key, generating a new key while keeping the old key valid during a grace period. This allows merchants to rotate their API keys seamlessly without service interruption. Both keys will work during the grace period.","operationId":"HubwalletPaymentGatewayWeb.Controller.Merchant.Default.refresh_api_key","parameters":[],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Refresh_API_Key_Request"}}},"description":"API key refresh parameters","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Refresh_API_Key_Response"}}},"description":"API key refreshed successfully"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error_Response"}}},"description":"Key already deprecated, expired, or invalid"},"404":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error_Response"}}},"description":"API key not found"},"429":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error_Response"}}},"description":"Rate limit exceeded"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error_Response"}}},"description":"Unexpected error occurred"}},"summary":"Refresh API key with grace period","tags":["merchant"]}}},"components":{"schemas":{"Refresh_API_Key_Request":{"description":"Request to refresh an existing API key with a grace period","properties":{"api_key":{"description":"The actual API key to refresh","type":"string"},"grace_period_minutes":{"description":"Grace period in minutes during which both old and new API keys are valid (1-60 minutes)","maximum":60,"minimum":1,"nullable":true,"type":"integer"},"name":{"description":"Optional new name for the API key","nullable":true,"type":"string"}},"required":["api_key"],"title":"Refresh_API_Key_Request","type":"object"},"Refresh_API_Key_Response":{"description":"Response for API key refresh operation","properties":{"data":{"properties":{"grace_period":{"properties":{"ends_at":{"description":"ISO8601 timestamp when the grace period ends","format":"date-time","type":"string"},"minutes":{"description":"Duration of the grace period in minutes","type":"integer"}},"required":["minutes","ends_at"],"type":"object"},"message":{"description":"Informational message about the API key refresh","type":"string"},"new_api_key":{"description":"The new API key to use","type":"string"},"new_api_key_hint":{"description":"A hint of the new API key (first and last few characters)","type":"string"},"new_api_key_id":{"description":"The ID of the new API key","type":"string"},"old_api_key_id":{"description":"The ID of the old API key that was replaced","type":"string"}},"required":["new_api_key","new_api_key_id","new_api_key_hint","old_api_key_id","grace_period","message"],"type":"object"},"success":{"description":"Operation success status","type":"boolean"}},"required":["success","data"],"title":"Refresh_API_Key_Response","type":"object"},"Error_Response":{"description":"Error response format","properties":{"error":{"description":"Error flag, always true","type":"boolean"},"message":{"description":"Error message describing what went wrong","type":"string"},"request_id":{"description":"Request correlation ID for tracking and debugging","type":"string"},"status":{"description":"Transaction status when a transaction was created before the error (e.g. `\"failed\"` for a withdrawal that was submitted but failed)","nullable":true,"type":"string"},"transaction_uuid":{"description":"Database transaction UUID (only present when a transaction exists)","format":"uuid","nullable":true,"type":"string"}},"required":["error","message","request_id"],"title":"Error_Response","type":"object"}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.pay.io/api-reference/merchant-console-api/refresh-api-key.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
