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

# Create a key (write)

> Add a new key to the project. You may seed its values in one call via the `values` map. On a protected main branch, target a branch with `?branch=` instead — direct main writes are rejected.

**Constraints:**
- The key must be well-formed: each segment (split on the project's key separator) may contain only letters, digits, `_` and `-`.
- Creating a key that already exists returns 409.



## OpenAPI

````yaml /openapi/textsetu.json post /projects/{projectId}/keys
openapi: 3.1.0
info:
  title: TextSetu API
  version: 1.2.0
  description: >-
    Public REST API for TextSetu. Authenticate with a Personal Access Token
    (tsu_pat_…) or a project token (tsu_proj_…) via the `Authorization: Bearer
    <token>` header.


    **Authorization is permission-based.** Every token carries an explicit
    allow-list of RBAC permission keys (e.g. `translation_read`), and each
    endpoint declares the permission it requires (`x-permission`). A token's
    effective access is its underlying authority ∩ its allow-list — a PAT is
    further bounded by its owner's role-based permissions, so it can only
    narrow, never exceed, what the owner already has. A project token is bound
    to a single project. There are no coarse read/write/manage scopes.


    **Response envelope.** Every endpoint returns `{ "success": true, "data": …
    }` on success and `{ "success": false, "error": { "code", "message" } }` on
    failure.


    **Rate limit.** 600 requests/minute, keyed by token (or by IP when
    unauthenticated). Exceeding it returns 429 with the standard error envelope.
servers:
  - url: https://api.textsetu.com/api/v1
    description: Production
  - url: /api/v1
    description: This server (self-hosted / same-origin)
security:
  - bearerAuth: []
tags:
  - name: Projects
    description: >-
      Read project metadata — settings, key separator, and the
      approval/branching flags that shape how the other endpoints behave.
  - name: Languages
    description: >-
      List and manage a project's target languages. Each language is referenced
      by its BCP-47 code; the source language is flagged separately.
  - name: Translations
    description: >-
      Manage a project's translations: create, read, update, and delete
      translation keys — the identifiers your app looks up, carrying metadata
      (description, tags, screenshot) — and set the translated value for a key
      in a given language. Value writes honor the project's approval workflow —
      non-approver writes land as `pending_review`.
  - name: Stats
    description: >-
      Per-language completeness and approval progress for a project — the
      numbers behind the dashboard.
  - name: Import/Export
    description: >-
      Bulk-load source files into a project or export the current translations.
      Supports the same file formats as the web app.
  - name: Branches
    description: >-
      Work on translations in isolation and merge them back. Branch reads/writes
      mirror the main endpoints but stage changes as a diff until merge. See the
      [branching guide](/docs/guides/branches).
  - name: Glossary
    description: >-
      Manage term bases — approved terminology and its translations — and check
      a string against them. See the [glossary guide](/docs/guides/glossary).
  - name: Translation Memory
    description: >-
      Reusable translation stores. Fuzzy-match and concordance-search prior
      translations to reuse them. See the [translation memory
      guide](/docs/guides/translation-memory).
  - name: AI
    description: >-
      Machine-translate a project with the org's configured AI engine (brand
      voice, glossary/TM grounding, and an optional review pass). Runs
      asynchronously — start a run and poll the returned `jobId`.
  - name: Webhooks
    description: >-
      Get notified when a project's translations change, instead of polling.
      Register an HTTPS endpoint, subscribe it to the events you care about, and
      TextSetu POSTs a signed payload whenever one occurs. Payloads follow the
      [Standard Webhooks](https://www.standardwebhooks.com) spec — verify the
      `webhook-signature` header with any compatible library. Delivery is
      at-least-once and unordered, so treat `webhook-id` as an idempotency key.
      Failed deliveries are retried five times over roughly seven hours, and
      every attempt is inspectable and replayable via the delivery log.
  - name: Meta
    description: Service-level and cross-cutting endpoints.
paths:
  /projects/{projectId}/keys:
    post:
      tags:
        - Translations
      summary: Create a key (write)
      description: >-
        Add a new key to the project. You may seed its values in one call via
        the `values` map. On a protected main branch, target a branch with
        `?branch=` instead — direct main writes are rejected.


        **Constraints:**

        - The key must be well-formed: each segment (split on the project's key
        separator) may contain only letters, digits, `_` and `-`.

        - Creating a key that already exists returns 409.
      parameters:
        - name: projectId
          in: path
          required: true
          schema:
            type: string
          description: Project id (UUID) or id-embedded path slug.
        - name: branch
          in: query
          schema:
            type: string
          description: >-
            Target an open translation branch instead of main. Required when the
            project's main branch is protected.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                key:
                  type: string
                  minLength: 1
                  maxLength: 500
                  description: >-
                    Lookup identifier. Segments (split on the project separator)
                    may contain only letters, digits, `_` and `-`.
                  examples:
                    - home.hero.title
                description:
                  description: Optional translator-facing context for the key.
                  examples:
                    - Headline shown on the landing page hero.
                  type: string
                  maxLength: 1000
                tags:
                  description: Up to 20 labels for filtering and organizing keys.
                  examples:
                    - - marketing
                      - landing
                  maxItems: 20
                  type: array
                  items:
                    type: string
                    maxLength: 50
                isPlural:
                  description: >-
                    Set true to make this a plural key (values are keyed by CLDR
                    plural form).
                  type: boolean
                values:
                  description: >-
                    Optional initial values, keyed by language code. Singular:
                    `{ "fr": "…" }`; plural: `{ "fr": { "one": "…", "other": "…"
                    } }`.
                  examples:
                    - en: Welcome
                      fr: Bienvenue
                  type: object
                  propertyNames:
                    type: string
                  additionalProperties:
                    anyOf:
                      - type: string
                      - type: object
                        propertyNames:
                          type: string
                          enum:
                            - zero
                            - one
                            - two
                            - few
                            - many
                            - other
                        additionalProperties:
                          type: string
                        required:
                          - zero
                          - one
                          - two
                          - few
                          - many
                          - other
              required:
                - key
      responses:
        '201':
          description: The created key's metadata.
          content:
            application/json:
              schema:
                type: object
                required:
                  - success
                  - data
                properties:
                  success:
                    type: boolean
                    const: true
                  data:
                    type: object
                    properties:
                      key:
                        type: object
                        properties:
                          id:
                            type: string
                            description: Unique key id (UUID).
                            examples:
                              - a1b2c3d4-0000-4000-8000-000000000001
                          projectId:
                            type: string
                            description: Id of the project this key belongs to.
                            examples:
                              - proj_9f8e7d6c
                          key:
                            type: string
                            description: >-
                              The lookup identifier your app resolves, e.g.
                              `home.hero.title`.
                            examples:
                              - home.hero.title
                          description:
                            anyOf:
                              - type: string
                              - type: 'null'
                            description: >-
                              Optional note giving translators context for this
                              key.
                            examples:
                              - Headline shown on the landing page hero.
                          tags:
                            type: array
                            items:
                              type: string
                            description: >-
                              Free-form labels for filtering and organizing
                              keys.
                            examples:
                              - - marketing
                                - landing
                          isPlural:
                            type: boolean
                            description: >-
                              True when the key holds CLDR plural forms rather
                              than a single string.
                            examples:
                              - false
                          screenshotUrl:
                            anyOf:
                              - type: string
                              - type: 'null'
                            description: >-
                              Public URL of an attached screenshot showing the
                              key in context, if any.
                            examples:
                              - null
                          screenshotFileId:
                            anyOf:
                              - type: string
                              - type: 'null'
                            description: Storage id of the attached screenshot, if any.
                            examples:
                              - null
                          keySource:
                            type: string
                            enum:
                              - main
                              - branch
                            description: >-
                              Whether the effective row comes from `main` or a
                              branch overlay.
                            examples:
                              - main
                          createdAt:
                            type: string
                            description: Creation timestamp (ISO 8601).
                            examples:
                              - '2026-01-15T09:24:00.000Z'
                          updatedAt:
                            type: string
                            description: Last-update timestamp (ISO 8601).
                            examples:
                              - '2026-02-02T14:05:00.000Z'
                        required:
                          - id
                          - projectId
                          - key
                          - description
                          - tags
                          - isPlural
                          - screenshotUrl
                          - screenshotFileId
                          - keySource
                          - createdAt
                          - updatedAt
                        additionalProperties: false
                    required:
                      - key
                    additionalProperties: false
        '400':
          description: Malformed key or invalid body.
        '403':
          description: >-
            Direct edits to a protected main branch are blocked — target a
            branch.
        '404':
          description: Project not found.
        '409':
          description: A key with this name already exists.
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        API token: tsu_pat_… (PAT) or tsu_proj_… (project token). The token's
        granted RBAC permissions determine access; see each operation's
        `x-permission`.

````