For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://modelgates.ai/docs/_mcp/server.

Exchange authorization code for API key

POST https://modelgates.ai/api/v1/auth/keys Content-Type: application/json

Exchange an authorization code from the PKCE flow for a user-controlled API key

Reference: https://modelgates.ai/docs/api/api-reference/o-auth/exchange-auth-code-for-api-key

OpenAPI Specification

yaml
openapi: 3.1.0info:  title: ModelGates API  version: 1.0.0paths:  /auth/keys:    post:      operationId: exchange-auth-code-for-api-key      summary: Exchange authorization code for API key      description: >-        Exchange an authorization code from the PKCE flow for 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 exchanged code for an API key          content:            application/json:              schema:                $ref: >-                  #/components/schemas/OAuth_exchangeAuthCodeForAPIKey_Response_200        '400':          description: Bad Request - Invalid request parameters or malformed input          content:            application/json:              schema:                $ref: '#/components/schemas/BadRequestResponse'        '403':          description: Forbidden - Authentication successful but insufficient permissions          content:            application/json:              schema:                $ref: '#/components/schemas/ForbiddenResponse'        '500':          description: Internal Server Error - Unexpected server error          content:            application/json:              schema:                $ref: '#/components/schemas/InternalServerResponse'      requestBody:        content:          application/json:            schema:              type: object              properties:                code:                  type: string                  description: The authorization code received from the OAuth redirect                code_challenge_method:                  oneOf:                    - $ref: >-                        #/components/schemas/AuthKeysPostRequestBodyContentApplicationJsonSchemaCodeChallengeMethod                    - type: 'null'                  description: The method used to generate the code challenge                code_verifier:                  type: string                  description: >-                    The code verifier if code_challenge was used in the                    authorization request              required:                - codeservers:  - url: https://modelgates.ai/api/v1components:  schemas:    AuthKeysPostRequestBodyContentApplicationJsonSchemaCodeChallengeMethod:      type: string      enum:        - S256        - plain      description: The method used to generate the code challenge      title: AuthKeysPostRequestBodyContentApplicationJsonSchemaCodeChallengeMethod    OAuth_exchangeAuthCodeForAPIKey_Response_200:      type: object      properties:        key:          type: string          description: The API key to use for ModelGates requests        user_id:          type:            - string            - 'null'          description: User ID associated with the API key      required:        - key        - user_id      title: OAuth_exchangeAuthCodeForAPIKey_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    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    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 header

SDK Code Examples

python
import requests url = "https://modelgates.ai/api/v1/auth/keys" payload = {    "code": "auth_code_abc123def456",    "code_challenge_method": "S256",    "code_verifier": "dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk"}headers = {    "Authorization": "Bearer <token>",    "Content-Type": "application/json"} response = requests.post(url, json=payload, headers=headers) print(response.json())