For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://modelgates.ai/docs/_mcp/server.
Create authorization code
POST https://modelgates.ai/api/v1/auth/keys/code Content-Type: application/json
Create an authorization code for the PKCE flow to generate a user-controlled API key
Reference: https://modelgates.ai/docs/api/api-reference/o-auth/create-auth-keys-code
OpenAPI Specification
yaml
openapi: 3.1.0info: title: ModelGates API version: 1.0.0paths: /auth/keys/code: post: operationId: create-auth-keys-code summary: Create authorization code description: >- Create an authorization code for the PKCE flow to generate a user-controlled API key tags: - subpackage_oAuth parameters: - name: Authorization in: header description: API key as bearer token in Authorization header required: true schema: type: string responses: '200': description: Successfully created authorization code content: application/json: schema: $ref: '#/components/schemas/OAuth_createAuthKeysCode_Response_200' '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' '409': description: Conflict - Resource conflict or concurrent modification content: application/json: schema: $ref: '#/components/schemas/ConflictResponse' '500': description: Internal Server Error - Unexpected server error content: application/json: schema: $ref: '#/components/schemas/InternalServerResponse' requestBody: content: application/json: schema: type: object properties: callback_url: type: string format: uri description: >- The callback URL to redirect to after authorization. Note, only https URLs on ports 443 and 3000 are allowed. code_challenge: type: string description: PKCE code challenge for enhanced security code_challenge_method: $ref: >- #/components/schemas/AuthKeysCodePostRequestBodyContentApplicationJsonSchemaCodeChallengeMethod description: The method used to generate the code challenge expires_at: type: - string - 'null' format: date-time description: Optional expiration time for the API key to be created key_label: type: string description: >- Optional custom label for the API key. Defaults to the app name if not provided. limit: type: number format: double description: Credit limit for the API key to be created usage_limit_type: $ref: >- #/components/schemas/AuthKeysCodePostRequestBodyContentApplicationJsonSchemaUsageLimitType description: >- Optional credit limit reset interval. When set, the credit limit resets on this interval. required: - callback_urlservers: - url: https://modelgates.ai/api/v1components: schemas: AuthKeysCodePostRequestBodyContentApplicationJsonSchemaCodeChallengeMethod: type: string enum: - S256 - plain description: The method used to generate the code challenge title: >- AuthKeysCodePostRequestBodyContentApplicationJsonSchemaCodeChallengeMethod AuthKeysCodePostRequestBodyContentApplicationJsonSchemaUsageLimitType: type: string enum: - daily - weekly - monthly description: >- Optional credit limit reset interval. When set, the credit limit resets on this interval. title: AuthKeysCodePostRequestBodyContentApplicationJsonSchemaUsageLimitType AuthKeysCodePostResponsesContentApplicationJsonSchemaData: type: object properties: app_id: type: integer description: The application ID associated with this auth code created_at: type: string description: ISO 8601 timestamp of when the auth code was created id: type: string description: The authorization code ID to use in the exchange request required: - app_id - created_at - id description: Auth code data title: AuthKeysCodePostResponsesContentApplicationJsonSchemaData OAuth_createAuthKeysCode_Response_200: type: object properties: data: $ref: >- #/components/schemas/AuthKeysCodePostResponsesContentApplicationJsonSchemaData description: Auth code data required: - data title: OAuth_createAuthKeysCode_Response_200 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 ConflictResponseErrorData: type: object properties: code: type: integer message: type: string metadata: type: - object - 'null' additionalProperties: description: Any type required: - code - message description: Error data for ConflictResponse title: ConflictResponseErrorData ConflictResponse: type: object properties: error: $ref: '#/components/schemas/ConflictResponseErrorData' modelgates_metadata: type: - object - 'null' additionalProperties: description: Any type user_id: type: - string - 'null' required: - error description: Conflict - Resource conflict or concurrent modification title: ConflictResponse 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/auth/keys/code" payload = { "callback_url": "https://myapp.com/auth/callback", "code_challenge": "E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM", "code_challenge_method": "S256", "limit": 100}headers = { "Authorization": "Bearer <token>", "Content-Type": "application/json"} response = requests.post(url, json=payload, headers=headers) print(response.json())