> ## Documentation Index
> Fetch the complete documentation index at: https://docs.baseten.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Create an API key

> Mint a federated API key under a Frontier Gateway group. The plaintext key is returned exactly once.

Mint a new federated API key under an existing group. The key inherits the group's effective model set and limits; the request body does not configure either on the key. The plaintext key is returned exactly once in the response and is unrecoverable afterward.

### Errors

| Status          | Meaning                                                                                    |
| --------------- | ------------------------------------------------------------------------------------------ |
| `403 Forbidden` | The group exists but isn't in your workspace, or the caller doesn't have management scope. |
| `404 Not Found` | No group with this `id` in your workspace, or it has been deleted.                         |

<RequestExample>
  ```bash curl theme={"system"}
  curl --request POST \
    --url https://api.baseten.co/v1/gateway/groups/abc123hash/api_keys \
    --header "Authorization: Api-Key $BASETEN_API_KEY" \
    --header "Content-Type: application/json" \
    --data '{
      "name": "prod-key-1"
    }'
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={"system"}
  {
    "api_key": "sky_sCqhBwEy4kPd.<api-key-secret>",
    "prefix": "sky_sCqhBwEy4kPd",
    "name": "prod-key-1"
  }
  ```
</ResponseExample>


## OpenAPI

````yaml post /v1/gateway/groups/{group_id}/api_keys
openapi: 3.1.0
info:
  description: REST API for management of Baseten resources
  title: Baseten management API
  version: 1.0.0
servers:
  - url: https://api.baseten.co
security:
  - BearerAuth: []
paths:
  /v1/gateway/groups/{group_id}/api_keys:
    parameters:
      - $ref: '#/components/parameters/group_id'
    post:
      summary: Creates an API key for a group
      description: Creates a new API key for the given group.
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateApiKeyForGroupRequestV1'
        required: true
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateApiKeyForGroupResponseV1'
      x-codeSamples:
        - lang: bash
          source: |-
            curl --request POST \
            --url https://api.baseten.co/v1/gateway/groups/{group_id}/api_keys \
            --header "Authorization: Bearer $BASETEN_API_KEY" \
            --data '{
              "name": "prod-key-1"
            }'
        - lang: python
          source: |-
            import requests
            import os
            API_KEY = os.environ.get("BASETEN_API_KEY", "<YOUR_API_KEY>")
            url = "https://api.baseten.co/v1/gateway/groups/{group_id}/api_keys"

            headers = {"Authorization": f"Bearer {API_KEY}"}

            response = requests.request(
                "POST",
                url,
                headers=headers,
                json={'name': 'prod-key-1'}
            )

            print(response.text)
components:
  parameters:
    group_id:
      schema:
        type: string
      name: group_id
      in: path
      required: true
  schemas:
    CreateApiKeyForGroupRequestV1:
      properties:
        name:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          description: Optional display name for the new key.
          examples:
            - prod-key-1
          title: Name
      title: CreateApiKeyForGroupRequestV1
      type: object
    CreateApiKeyForGroupResponseV1:
      properties:
        api_key:
          description: Plaintext key string, returned exactly once.
          title: Api Key
          type: string
        prefix:
          description: Key prefix (the part before the dot).
          title: Prefix
          type: string
        name:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          description: Display name of the key.
          title: Name
      required:
        - api_key
        - prefix
      title: CreateApiKeyForGroupResponseV1
      type: object
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: >-
        Send `Authorization: Bearer <api_key>`. The legacy `Authorization:
        Api-Key <api_key>` scheme is also accepted.

````