For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://modelgates.ai/docs/_mcp/server.
Create a new API key
POST https://modelgates.ai/api/v1/keys Content-Type: application/json
Create a new API key for the authenticated user. Management key required.
Reference: https://modelgates.ai/docs/api/api-reference/api-keys/create-keys
OpenAPI Specification
yaml
openapi: 3.1.0info: title: ModelGates API version: 1.0.0paths: /keys: post: operationId: create-keys summary: Create a new API key description: >- Create a new API key for the authenticated user. [Management key](/docs/guides/overview/auth/management-api-keys) required. tags: - subpackage_apiKeys parameters: - name: Authorization in: header description: API key as bearer token in Authorization header required: true schema: type: string responses: '201': description: API key created successfully content: application/json: schema: $ref: '#/components/schemas/API Keys_createKeys_Response_201' '400': description: Bad Request - Invalid request parameters or malformed input content: application/json: schema: $ref: '#/components/schemas/BadRequestResponse' '401': description: Unauthorized - Authentication required or invalid credentials content: application/json: schema: $ref: '#/components/schemas/UnauthorizedResponse' '403': description: Forbidden - Authentication successful but insufficient permissions content: application/json: schema: $ref: '#/components/schemas/ForbiddenResponse' '429': description: Too Many Requests - Rate limit exceeded content: application/json: schema: $ref: '#/components/schemas/TooManyRequestsResponse' '500': description: Internal Server Error - Unexpected server error content: application/json: schema: $ref: '#/components/schemas/InternalServerResponse' requestBody: content: application/json: schema: type: object properties: creator_user_id: type: - string - 'null' description: >- Optional user ID of the key creator. Only meaningful for organization-owned keys where a specific member is creating the key. expires_at: type: - string - 'null' format: date-time description: >- Optional ISO 8601 UTC timestamp when the API key should expire. Must be UTC, other timezones will be rejected include_byok_in_limit: type: boolean description: Whether to include BYOK usage in the limit limit: type: - number - 'null' format: double description: Optional spending limit for the API key in USD limit_reset: oneOf: - $ref: >- #/components/schemas/KeysPostRequestBodyContentApplicationJsonSchemaLimitReset - type: 'null' description: >- Type of limit reset for the API key (daily, weekly, monthly, or null for no reset). Resets happen automatically at midnight UTC, and weeks are Monday through Sunday. name: type: string description: Name for the new API key workspace_id: type: string format: uuid description: >- The workspace to create the API key in. Defaults to the default workspace if not provided. required: - nameservers: - url: https://modelgates.ai/api/v1components: schemas: KeysPostRequestBodyContentApplicationJsonSchemaLimitReset: type: string enum: - daily - weekly - monthly description: >- Type of limit reset for the API key (daily, weekly, monthly, or null for no reset). Resets happen automatically at midnight UTC, and weeks are Monday through Sunday. title: KeysPostRequestBodyContentApplicationJsonSchemaLimitReset KeysPostResponsesContentApplicationJsonSchemaData: type: object properties: byok_usage: type: number format: double description: Total external BYOK usage (in USD) for the API key byok_usage_daily: type: number format: double description: External BYOK usage (in USD) for the current UTC day byok_usage_monthly: type: number format: double description: External BYOK usage (in USD) for current UTC month byok_usage_weekly: type: number format: double description: >- External BYOK usage (in USD) for the current UTC week (Monday-Sunday) created_at: type: string description: ISO 8601 timestamp of when the API key was created creator_user_id: type: - string - 'null' description: >- The user ID of the key creator. For organization-owned keys, this is the member who created the key. For individual users, this is the user's own ID. disabled: type: boolean description: Whether the API key is disabled expires_at: type: - string - 'null' format: date-time description: >- ISO 8601 UTC timestamp when the API key expires, or null if no expiration hash: type: string description: Unique hash identifier for the API key include_byok_in_limit: type: boolean description: Whether to include external BYOK usage in the credit limit label: type: string description: Human-readable label for the API key limit: type: - number - 'null' format: double description: Spending limit for the API key in USD limit_remaining: type: - number - 'null' format: double description: Remaining spending limit in USD limit_reset: type: - string - 'null' description: Type of limit reset for the API key name: type: string description: Name of the API key updated_at: type: - string - 'null' description: ISO 8601 timestamp of when the API key was last updated usage: type: number format: double description: Total ModelGates credit usage (in USD) for the API key usage_daily: type: number format: double description: ModelGates credit usage (in USD) for the current UTC day usage_monthly: type: number format: double description: ModelGates credit usage (in USD) for the current UTC month usage_weekly: type: number format: double description: >- ModelGates credit usage (in USD) for the current UTC week (Monday-Sunday) workspace_id: type: string description: The workspace ID this API key belongs to. required: - byok_usage - byok_usage_daily - byok_usage_monthly - byok_usage_weekly - created_at - creator_user_id - disabled - hash - include_byok_in_limit - label - limit - limit_remaining - limit_reset - name - updated_at - usage - usage_daily - usage_monthly - usage_weekly - workspace_id description: The created API key information title: KeysPostResponsesContentApplicationJsonSchemaData API Keys_createKeys_Response_201: type: object properties: data: $ref: >- #/components/schemas/KeysPostResponsesContentApplicationJsonSchemaData description: The created API key information key: type: string description: The actual API key string (only shown once) required: - data - key title: API Keys_createKeys_Response_201 BadRequestResponseErrorData: type: object properties: code: type: integer message: type: string metadata: type: - object - 'null' additionalProperties: description: Any type required: - code - message description: Error data for BadRequestResponse title: BadRequestResponseErrorData BadRequestResponse: type: object properties: error: $ref: '#/components/schemas/BadRequestResponseErrorData' modelgates_metadata: type: - object - 'null' additionalProperties: description: Any type user_id: type: - string - 'null' required: - error description: Bad Request - Invalid request parameters or malformed input title: BadRequestResponse UnauthorizedResponseErrorData: type: object properties: code: type: integer message: type: string metadata: type: - object - 'null' additionalProperties: description: Any type required: - code - message description: Error data for UnauthorizedResponse title: UnauthorizedResponseErrorData UnauthorizedResponse: type: object properties: error: $ref: '#/components/schemas/UnauthorizedResponseErrorData' modelgates_metadata: type: - object - 'null' additionalProperties: description: Any type user_id: type: - string - 'null' required: - error description: Unauthorized - Authentication required or invalid credentials title: UnauthorizedResponse ForbiddenResponseErrorData: type: object properties: code: type: integer message: type: string metadata: type: - object - 'null' additionalProperties: description: Any type required: - code - message description: Error data for ForbiddenResponse title: ForbiddenResponseErrorData ForbiddenResponse: type: object properties: error: $ref: '#/components/schemas/ForbiddenResponseErrorData' modelgates_metadata: type: - object - 'null' additionalProperties: description: Any type user_id: type: - string - 'null' required: - error description: Forbidden - Authentication successful but insufficient permissions title: ForbiddenResponse TooManyRequestsResponseErrorData: type: object properties: code: type: integer message: type: string metadata: type: - object - 'null' additionalProperties: description: Any type required: - code - message description: Error data for TooManyRequestsResponse title: TooManyRequestsResponseErrorData TooManyRequestsResponse: type: object properties: error: $ref: '#/components/schemas/TooManyRequestsResponseErrorData' modelgates_metadata: type: - object - 'null' additionalProperties: description: Any type user_id: type: - string - 'null' required: - error description: Too Many Requests - Rate limit exceeded title: TooManyRequestsResponse InternalServerResponseErrorData: type: object properties: code: type: integer message: type: string metadata: type: - object - 'null' additionalProperties: description: Any type required: - code - message description: Error data for InternalServerResponse title: InternalServerResponseErrorData InternalServerResponse: type: object properties: error: $ref: '#/components/schemas/InternalServerResponseErrorData' modelgates_metadata: type: - object - 'null' additionalProperties: description: Any type user_id: type: - string - 'null' required: - error description: Internal Server Error - Unexpected server error title: InternalServerResponse securitySchemes: apiKey: type: http scheme: bearer description: API key as bearer token in Authorization headerSDK Code Examples
python
import requests url = "https://modelgates.ai/api/v1/keys" payload = { "name": "Analytics Service Key", "expires_at": "2029-11-30T23:59:59Z", "include_byok_in_limit": False, "limit": 100, "limit_reset": "weekly"}headers = { "Authorization": "Bearer <token>", "Content-Type": "application/json"} response = requests.post(url, json=payload, headers=headers) print(response.json())