---
title: "Create API key for a service account"
method: POST
path: "/service-accounts/{id}/api-keys"
tags: ["service_accounts"]
---

# Create API key for a service account

`POST /service-accounts/{id}/api-keys`

Create a new API key. The plaintext key is only returned once.

## Path parameters

- `id` string, required

## Request body

- CreateServiceAccountAPIKeyRequest
  - `expires_in_days` integer
  - `name` string

## Response `201`

Created

- ServiceAccountAPIKey
  - `created_at` string
  - `expires_at` string
  - `id` string
  - `key` string
  - `last_used_at` string
  - `name` string
  - `service_account_id` string

## Other responses

- `400` — Bad Request

## Changes

- **2026-07-06** `52fc33fb1e0a` — 1 info
  - endpoint added
- **2025-06-02** `0c070796939d` — 1 breaking
  - api path removed without deprecation

[Change history](https://skmtc.dev/marmotdata/apis/marmot-api/changes/service-accounts/:id/api-keys/post.md)

---

[API](https://skmtc.dev/marmotdata/apis/marmot-api.md) · [All operations](https://skmtc.dev/marmotdata/apis/marmot-api/llms.txt) · [OpenAPI document](https://skmtc.dev/marmotdata/apis/marmot-api/revisions/cadebfd78fef?raw)
