---
title: Create Key
description: Reference for the POST /console/v1/keys API endpoint.
product: general
token_estimate: 1149
---
# Create Key

> For AI agents: a documentation index is available at [/llms.txt](/llms.txt). Append `.md` to any page URL for markdown, or send `Accept: text/markdown`.

## Create Key

**POST** `/console/v1/keys`

Full URL: `https://statsigapi.net/console/v1/keys`

Create Key

## Authorizations

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| STATSIG-API-KEY | string | Yes | — | apiKey (header) |

## Body (application/json)

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| description | string | Yes | — | Constraints: max length: 1000 |
| type | string | Yes | — | Allowed values: SERVER, CLIENT, CONSOLE, SCIM, ORG |
| scopes | string[] | No | — | — |
| environments | string[] | No | — | — |
| targetAppID | string | No | — | — |
| secondaryTargetAppIDs | string[] | No | — | — |

## Response (application/json)

**200** — Key created successfully

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| message | string | Yes | — | A simple string explaining the result of the operation. |
| data | object | Yes | — | — |
| data.key | string | Yes | — | Constraints: nullable |
| data.type | string | Yes | — | Allowed values: SERVER, CLIENT, CONSOLE, SCIM, ORG |
| data.description | string | Yes | — | — |
| data.scopes | string[] | Yes | — | — |
| data.environments | string[] | No | — | — |
| data.primaryTargetApp | string | No | — | Constraints: nullable |
| data.secondaryTargetApps | string[] | No | — | Constraints: nullable |
| data.status | string | Yes | — | Allowed values: active, deactivated |
| data.lastUsed | string | No | — | Constraints: nullable |

```json
{
  "message": "Key created successfully.",
  "data": {
    "key": "secret-123",
    "type": "SERVER",
    "description": "Server secret key",
    "scopes": [],
    "environments": [
      "production"
    ],
    "primaryTargetApp": "primaryApp",
    "secondaryTargetApps": [
      "secondaryApp"
    ],
    "status": "active"
  }
}
```

**403** — Insufficient permissions.

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| status | integer | Yes | — | Allowed values: 403 |
| message | string | Yes | — | — |

```json
{
  "status": 403,
  "message": "Forbidden. The request was valid, but the server is refusing action. You might not have the necessary permissions to access the resource."
}
```

## Code samples

### cURL

```bash
curl -X POST "https://statsigapi.net/console/v1/keys" \
  -H "Content-Type: application/json" \
  -H "STATSIG-API-KEY: YOUR_API_KEY"
```

### Python

```python
import requests

response = requests.post(
    "https://statsigapi.net/console/v1/keys",
    headers={
        "Content-Type": "application/json",
        "STATSIG-API-KEY": "YOUR_API_KEY"
    }
)
data = response.json()
```

### JavaScript

```javascript
const response = await fetch("https://statsigapi.net/console/v1/keys", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "STATSIG-API-KEY": "YOUR_API_KEY"
  }
});
const data = await response.json();
```

### PHP

```php
<?php
$ch = curl_init("https://statsigapi.net/console/v1/keys");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Content-Type: application/json",
    "STATSIG-API-KEY: YOUR_API_KEY"
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
```

### Go

```go
package main

import (
  "bytes"
  "net/http"
)

func main() {
req, _ := http.NewRequest("POST", "https://statsigapi.net/console/v1/keys", nil)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("STATSIG-API-KEY", "YOUR_API_KEY")
  client := &http.Client{}
  resp, _ := client.Do(req)
  defer resp.Body.Close()
}
```

### Java

```java
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
      .uri(URI.create("https://statsigapi.net/console/v1/keys"))
      .method("POST", HttpRequest.BodyPublishers.noBody())
.header("Content-Type", "application/json")
      .header("STATSIG-API-KEY", "YOUR_API_KEY")
      .build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
```

### Ruby

```ruby
require "net/http"
require "json"

uri = URI("https://statsigapi.net/console/v1/keys")
request = Net::HTTP::Post.new(uri)
request["Content-Type"] = "application/json"
request["STATSIG-API-KEY"] = "YOUR_API_KEY"
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
  http.request(request)
end
```

