POST /auth/api-keys
Create a new API key for the authenticated user. The full key is returned only once.

Authentication

API Key (header: X-API-Key) API Key (cookie: better-auth.session_token)

Request Body required

Request body

application/json
name string REQUIRED
Display name for the key
org_id string REQUIRED
Organization ID
env_id string REQUIRED
Environment ID
scopes string
Scopes (default: *)

Responses

201 API key created (key shown once)
application/json
id string REQUIRED
Key ID
name string REQUIRED
Display name
key string REQUIRED
Full API key (shown once)
key_prefix string REQUIRED
Key prefix for identification
scopes string REQUIRED
Scopes
created_at string REQUIRED
ISO timestamp
400 Bad request
401 Unauthorized
404 Environment not found
curl -X POST 'https://hookstream.io/v1/auth/api-keys' \  -H 'Authorization: Bearer YOUR_API_TOKEN' \  -H 'Content-Type: application/json' \  -d '{  "name": "Production key",  "org_id": "string",  "env_id": "string",  "scopes": "*"}'
const response = await fetch('https://hookstream.io/v1/auth/api-keys', {  method: 'POST',  headers: {      "Authorization": "Bearer YOUR_API_TOKEN",      "Content-Type": "application/json"  },  body: JSON.stringify({    "name": "Production key",    "org_id": "string",    "env_id": "string",    "scopes": "*"  })});const data = await response.json();console.log(data);
import requestsheaders = {    'Authorization': 'Bearer YOUR_API_TOKEN'}response = requests.post('https://hookstream.io/v1/auth/api-keys', headers=headers, json={  "name": "Production key",  "org_id": "string",  "env_id": "string",  "scopes": "*"})print(response.json())
package mainimport (	"fmt"	"io"	"net/http"	"strings")func main() {	body := strings.NewReader(`{  "name": "Production key",  "org_id": "string",  "env_id": "string",  "scopes": "*"}`)	req, _ := http.NewRequest("POST", "https://hookstream.io/v1/auth/api-keys", body)	req.Header.Set("Authorization", "Bearer YOUR_API_TOKEN")	req.Header.Set("Content-Type", "application/json")	resp, _ := http.DefaultClient.Do(req)	defer resp.Body.Close()	result, _ := io.ReadAll(resp.Body)	fmt.Println(string(result))}
201 Response
{  "id": "<string>",  "name": "<string>",  "key": "<string>",  "key_prefix": "<string>",  "scopes": "<string>",  "created_at": "<string>"}