> For the complete documentation index, see [llms.txt](https://docs.lighter.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.lighter.xyz/api/api-keys/set-api-key-restrictions.md). Agents can also search and read this documentation through its [MCP server](https://docs.lighter.xyz/~gitbook/mcp).

# Set API key restrictions

Replace all restrictions on one API key: market whitelist, IP whitelist and expiry. The account's L1 wallet signs the request with personal\_sign, so someone who holds only the API private key cannot loosen the restrictions. They apply to every transaction the key signs except ChangePubKey. The IP whitelist and expiry also apply to every request authenticated with an auth token signed by the key. See [API key restrictions](https://docs.lighter.xyz/developers/integration-guides/api-keys#api-key-restrictions) for the signing message, timestamp rules and errors.

```json
{"openapi":"3.0.0","info":{"title":"Lighter API","version":"1.0.0"},"tags":[{"name":"api-keys"}],"servers":[{"url":"https://mainnet.zklighter.elliot.ai","description":"Lighter mainnet"},{"url":"https://api.testnet.lighter.xyz","description":"Lighter testnet"},{"url":"https://api.rh.lighter.xyz","description":"Lighter on Robinhood Chain mainnet"},{"url":"https://api.rh-testnet.lighter.xyz","description":"Lighter on Robinhood Chain testnet"}],"paths":{"/api/v1/setApiKeyRestrictions":{"post":{"summary":"Set API key restrictions","operationId":"setApiKeyRestrictions","tags":["api-keys"],"description":"Replace all restrictions on one API key: market whitelist, IP whitelist and expiry. The account's L1 wallet signs the request with personal_sign, so someone who holds only the API private key cannot loosen the restrictions. They apply to every transaction the key signs except ChangePubKey. The IP whitelist and expiry also apply to every request authenticated with an auth token signed by the key. See [API key restrictions](https://docs.lighter.xyz/developers/integration-guides/api-keys#api-key-restrictions) for the signing message, timestamp rules and errors.","requestBody":{"required":true,"content":{"application/x-www-form-urlencoded":{"schema":{"$ref":"#/components/schemas/ReqSetApiKeyRestrictions"}},"multipart/form-data":{"schema":{"$ref":"#/components/schemas/ReqSetApiKeyRestrictions"}}}},"responses":{"200":{"description":"A successful response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ResultCode"}}}},"400":{"description":"Bad request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ResultCode"}}}}}}}},"components":{"schemas":{"ReqSetApiKeyRestrictions":{"type":"object","title":"ReqSetApiKeyRestrictions","description":"Send as form data, not JSON. The values replace all restrictions on the key. List fields are JSON array strings and are signed exactly as sent.","properties":{"account_index":{"type":"integer","format":"int64","description":"Account that owns the key."},"api_key_index":{"type":"integer","format":"uint8","description":"0 to 254."},"public_key":{"type":"string","description":"The key's current public key in hex, as returned by apikeys. The 0x prefix is optional."},"market_ids":{"type":"string","description":"JSON array string of up to 16 public market ids, e.g. \"[0,1]\". Every id must be a current market. Use [] with no series for no market whitelist."},"series":{"type":"string","description":"JSON array string of up to 16 market series, e.g. [{\"creator_account_index\":3,\"tag\":\"btc-updown-5m\"}]. tag is 1 to 100 characters. Defaults to []."},"allowed_ips":{"type":"string","description":"JSON array string of up to 16 IPv4 or IPv6 addresses, e.g. [\"203.0.113.7\"]. CIDR ranges are not accepted. Defaults to [], which allows any IP."},"valid_until":{"type":"integer","format":"int64","description":"Unix seconds when the key expires, in the future and at most 180 days ahead. 0 means no expiry."},"timestamp":{"type":"integer","format":"int64","description":"Unix seconds when signed. Must be within 10 minutes of server time and greater than the timestamp of the restrictions stored for this key index."},"signature":{"type":"string","description":"0x-prefixed personal_sign signature of the signing message by the account's L1 address."}},"required":["account_index","api_key_index","public_key","market_ids","valid_until","timestamp","signature"]},"ResultCode":{"type":"object","properties":{"code":{"type":"integer","format":"int32"},"message":{"type":"string"}},"title":"ResultCode","required":["code"]}}}}
```


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.lighter.xyz/api/api-keys/set-api-key-restrictions.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
