Use the ably auth keys create command to create a new API key for an app.
Synopsis
ably auth keys create <key-name> [options]Arguments
key-name Required
The name for the new API key.
Options
--app
The app ID to create the key for. Uses the currently selected app if not specified.
--capabilities
The capabilities for the key, specified as either a JSON object for per-channel capabilities or a comma-separated list applied to all channels. Defaults to '{"*":["*"]}'. Available operations are subscribe, publish, presence, history, stats, channel-metadata, push-subscribe, push-admin, privileged-headers, object-subscribe, object-publish, annotation-subscribe, annotation-publish, message-update-own, message-update-any, message-delete-own, and message-delete-any.
--json
Output results as compact JSON. Mutually exclusive with --pretty-json.
--pretty-json
Output results in formatted JSON. Mutually exclusive with --json.
--verbose | -v
Enable verbose logging. Can be combined with --json or --pretty-json.
Examples
Create a basic API key:
ably auth keys create "My New Key"Create a key with specific capabilities:
ably auth keys create "My New Key" --capabilities '{"my-channel":["publish"]}'Create an API key for a specific app:
ably auth keys create "My New Key" --app APP_IDCreate a key with wildcard capabilities:
ably auth keys create "My New Key" --capabilities '{"*":["*"]}'Create a key with capabilities for multiple channels:
ably auth keys create "My New Key" --capabilities '{"channel1":["publish","subscribe"],"channel2":["history"]}'Create a key using a comma-separated list of capabilities applied to all channels:
ably auth keys create "My New Key" --capabilities "publish,subscribe"Create a key with namespace-scoped publish capability:
ably auth keys create "MyKey" --app APP_ID --capabilities '{"channel:*":["publish"]}'Create a key with mixed capabilities for a specific app:
ably auth keys create "MyOtherKey" --app APP_ID --capabilities '{"channel:chat-*":["subscribe"],"channel:updates":["publish"]}'Create a key and output the result in JSON format:
ably auth keys create "My New Key" --jsonCreate a key and output the result in formatted JSON:
ably auth keys create "My New Key" --pretty-jsonSee also
- Auth — Explore all
ably authcommands. - CLI reference — Full list of available commands.