---
updatedAt: 2026-03-24T22:29:34.000Z
agentTools:
  projectIndex: https://developers.digitalfemsa.io/llms.txt
---

# Create Api Key

Creates a new API key.

The response includes an `authentication_token` that is shown only once (at creation time).
Copy and store it securely.


# OpenAPI definition

```json
{
  "openapi": "3.0.3",
  "info": {
    "contact": {
      "email": "engineering@femsa.com",
      "name": "Engineering Femsa",
      "url": "https://github.com/digitalfemsa/openapi/issues"
    },
    "description": "Femsa sdk",
    "license": {
      "name": "MIT-LICENSE",
      "url": "https://www.apache.org/licenses/LICENSE-2.0.html"
    },
    "title": "Femsa API",
    "version": "2.1.0"
  },
  "servers": [
    {
      "description": "Femsa main server",
      "url": "https://api.digitalfemsa.io"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/api_keys": {
      "post": {
        "description": "Creates a new API key.\n\nThe response includes an `authentication_token` that is shown only once (at creation time).\nCopy and store it securely.\n",
        "operationId": "createApiKey",
        "parameters": [
          {
            "description": "Use for knowing which language to use",
            "examples": {
              "es": {
                "summary": "for spanish request/response",
                "value": "es"
              },
              "en": {
                "summary": "for english request/response",
                "value": "en"
              }
            },
            "in": "header",
            "name": "Accept-Language",
            "required": false,
            "schema": {
              "default": "es",
              "enum": [
                "es",
                "en"
              ],
              "type": "string"
            }
          },
          {
            "description": "In the case of a holding company, the company id of the child company to which will process the request.",
            "example": "6441b6376b60c3a638da80af",
            "in": "header",
            "name": "X-Child-Company-Id",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "$ref": "#/components/requestBodies/api_keys_create"
        },
        "responses": {
          "200": {
            "content": {
              "application/vnd.app-v2.1.0+json": {
                "schema": {
                  "$ref": "#/components/schemas/api_key_create_response"
                }
              }
            },
            "description": "successful operation"
          },
          "401": {
            "content": {
              "application/vnd.app-v2.1.0+json": {
                "example": {
                  "details": [
                    {
                      "message": "Please include your access key in your request.",
                      "param": null,
                      "code": "femsa.errors.authentication.missing_key"
                    }
                  ],
                  "log_id": "507f1f77bcf86cd799439011",
                  "object": "error",
                  "type": "authentication_error"
                },
                "schema": {
                  "$ref": "#/components/schemas/error"
                }
              }
            },
            "description": "authentication error"
          },
          "422": {
            "content": {
              "application/vnd.app-v2.1.0+json": {
                "example": {
                  "details": [
                    {
                      "message": "The name does not exist.",
                      "param": "payment_method.name",
                      "code": "femsa.errors.parameter_validation.payment_method.name.nonexistent_token",
                      "debug_message": "The name does not exist."
                    }
                  ],
                  "log_id": "641b6d813cd9a50001515017",
                  "object": "error",
                  "type": "parameter_validation_error"
                },
                "schema": {
                  "$ref": "#/components/schemas/error"
                }
              }
            },
            "description": "parameter validation error"
          },
          "500": {
            "content": {
              "application/vnd.app-v2.1.0+json": {
                "example": {
                  "details": [
                    {
                      "debug_message": "There was a runtime error and Femsa engineers have been notified.",
                      "message": "There was a runtime error and Femsa engineers have been notified.",
                      "param": null,
                      "code": "femsa.errors.api.system.general_failure"
                    }
                  ],
                  "object": "error",
                  "type": "api_error",
                  "log_id": "641b6f2b3cd9a50001515098"
                },
                "schema": {
                  "$ref": "#/components/schemas/error"
                }
              }
            },
            "description": "internal server error"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Create API key",
        "tags": [
          "Api Keys"
        ]
      }
    }
  },
  "components": {
    "requestBodies": {
      "api_keys_create": {
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/api_key_request"
            }
          }
        },
        "description": "requested field for a api keys",
        "required": true
      }
    },
    "schemas": {
      "api_key_response": {
        "description": "api keys model",
        "properties": {
          "active": {
            "description": "Indicates if the api key is active",
            "example": true,
            "type": "boolean"
          },
          "created_at": {
            "description": "Unix timestamp in seconds of when the api key was created",
            "example": 1684167881,
            "format": "int64",
            "type": "integer"
          },
          "updated_at": {
            "description": "Unix timestamp in seconds of when the api key was last updated",
            "example": 1684167923,
            "format": "int64",
            "type": "integer"
          },
          "deactivated_at": {
            "description": "Unix timestamp in seconds of when the api key was deleted",
            "format": "int64",
            "nullable": true,
            "type": "integer",
            "example": null
          },
          "description": {
            "description": "A name or brief explanation of what this api key is used for",
            "example": "online store",
            "type": "string"
          },
          "id": {
            "description": "Unique identifier of the api key",
            "example": "64625cc9f3e02c00163f5e4d",
            "type": "string"
          },
          "livemode": {
            "description": "Indicates if the api key is in production",
            "example": false,
            "type": "boolean"
          },
          "deleted": {
            "description": "Indicates if the api key was deleted",
            "example": false,
            "type": "boolean"
          },
          "object": {
            "description": "Object name, value is 'api_key'",
            "example": "api_key",
            "type": "string"
          },
          "prefix": {
            "description": "The first few characters of the authentication_token",
            "example": "key_rp",
            "type": "string"
          },
          "role": {
            "description": "Indicates if the api key is private or public",
            "example": "private",
            "type": "string"
          }
        },
        "title": "api_key_response",
        "type": "object"
      },
      "error": {
        "allOf": [
          {
            "$ref": "#/components/schemas/details"
          },
          {
            "properties": {
              "log_id": {
                "description": "log id",
                "example": "507f1f77bcf86cd799439011",
                "nullable": true,
                "type": "string"
              },
              "type": {
                "example": "authentication_error",
                "type": "string"
              },
              "object": {
                "example": "error",
                "type": "string"
              }
            },
            "type": "object"
          }
        ],
        "description": "err model",
        "title": "error"
      },
      "api_key_request": {
        "properties": {
          "description": {
            "description": "A name or brief explanation of what this API key is used for.",
            "example": "online store",
            "type": "string"
          },
          "role": {
            "description": "Defines the type of API key to create. Only \"private\" is supported for creation. A \"public\" API key already exists by default per company/environment.\n",
            "enum": [
              "private"
            ],
            "example": "private",
            "type": "string"
          }
        },
        "required": [
          "role"
        ],
        "title": "api_keys_request",
        "type": "object"
      },
      "details": {
        "properties": {
          "details": {
            "items": {
              "$ref": "#/components/schemas/details_error"
            },
            "type": "array"
          }
        },
        "type": "object"
      },
      "api_key_create_response": {
        "allOf": [
          {
            "properties": {
              "authentication_token": {
                "description": "Used as the username for Basic Authentication, with a blank password. This value is shown only once (when the key is created). Copy and store it securely.\n",
                "example": "key_rpHzxufNgjFCdprEEFZRTKi",
                "type": "string"
              }
            },
            "type": "object"
          },
          {
            "$ref": "#/components/schemas/api_key_response"
          }
        ],
        "title": "api_key_create_response"
      },
      "details_error": {
        "properties": {
          "code": {
            "example": "femsa.errors.authentication.missing_key",
            "type": "string"
          },
          "param": {
            "nullable": true,
            "type": "string"
          },
          "message": {
            "example": "Acceso no autorizado.",
            "type": "string"
          },
          "debug_message": {
            "example": "Please include your access key in your request.",
            "type": "string"
          }
        },
        "title": "details_error",
        "type": "object"
      }
    },
    "securitySchemes": {
      "bearerAuth": {
        "scheme": "bearer",
        "type": "http"
      }
    }
  }
}
```