openapi: 3.0.0
info:
  title: Unkey API
  version: 1.0.0
servers:
  - url: https://api.unkey.dev
  - url: http://localhost
paths:
  /v1/ratelimit.commitLease:
    post:
      operationId: v1.ratelimit.commitLease
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/V1RatelimitCommitLeaseRequestBody'
        required: true
      responses:
        '204':
          description: No Content
        '400':
          description: Bad request
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/ValidationError'
        '500':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/BaseError'
          description: Error
      tags:
        - ratelimit
components:
  schemas:
    BaseError:
      properties:
        requestId:
          description: A unique id for this request. Please always provide this to support.
          example: req_123
          type: string
        detail:
          description: A human-readable explanation specific to this occurrence of the problem.
          example: Property foo is required but is missing.
          type: string
        instance:
          description: A URI reference that identifies the specific occurrence of the problem.
          example: https://example.com/error-log/abc123
          format: uri
          type: string
        status:
          description: HTTP status code
          example: 400
          format: int
          type: integer
        title:
          description: A short, human-readable summary of the problem type. This value should not change between occurrences of the error.
          example: Bad Request
          type: string
        type:
          default: about:blank
          description: A URI reference to human-readable documentation for the error.
          example: https://example.com/errors/example
          format: uri
          type: string
      type: object
      required:
        - requestId
        - detail
        - instance
        - status
        - title
        - type
    ValidationError:
      additionalProperties: false
      properties:
        requestId:
          description: A unique id for this request. Please always provide this to support.
          example: req_123
          type: string
        detail:
          description: A human-readable explanation specific to this occurrence of the problem.
          example: Property foo is required but is missing.
          type: string
        errors:
          description: Optional list of individual error details
          items:
            $ref: '#/components/schemas/ValidationErrorDetail'
          type:
            - array
        instance:
          description: A URI reference that identifies the specific occurrence of the problem.
          example: https://example.com/error-log/abc123
          format: uri
          type: string
        status:
          description: HTTP status code
          example: 400
          format: int
          type: integer
        title:
          description: A short, human-readable summary of the problem type. This value should not change between occurrences of the error.
          example: Bad Request
          type: string
        type:
          default: about:blank
          description: A URI reference to human-readable documentation for the error.
          example: https://example.com/errors/example
          format: uri
          type: string
      type: object
      required:
        - requestId
        - detail
        - instance
        - status
        - title
        - type
        - errors
    ValidationErrorDetail:
      additionalProperties: false
      properties:
        location:
          description: Where the error occurred, e.g. 'body.items[3].tags' or 'path.thing-id'
          type: string
        message:
          description: Error message text
          type: string
        fix:
          description: A human-readable message describing how to fix the error.
          type: string
      type: object
      required:
        - message
        - location
    V1RatelimitCommitLeaseRequestBody:
      additionalProperties: false
      properties:
        $schema:
          description: A URL to the JSON Schema for this object.
          example: https://api.unkey.dev/schemas/V1RatelimitCommitLeaseRequestBody.json
          format: uri
          readOnly: true
          type: string
        cost:
          description: The actual cost of the request.
          format: int64
          type: integer
        lease:
          description: The lease you received from the ratelimit response.
          type: string
      required:
        - lease
        - cost
      type: object

---
To implement the `POST /v1/ratelimit.commitLease` route in the `ExampleClient` class, we will create a new method called `commitLease`. This method will:

1. **Define the route path, method, and tags** in a comment above the method.
2. **Use the `fetch` method** to make the API call.
3. **Handle request serialization** by accepting a parameter of type `V1RatelimitCommitLeaseRequestBody`.
4. **Handle response serialization** by checking for the status code and returning appropriate types.
5. **Implement error handling** for both `400` and `500` status codes, returning the appropriate error types defined in the `components.ts` file.

Here’s the code snippet to be added to the `./client.ts` file:

```typescript:client.ts
  // POST /v1/ratelimit.commitLease
  // Tags: ratelimit
  async commitLease(
    body: types.V1RatelimitCommitLeaseRequestBody
  ): Promise<void> {
    const response = await this.fetch({
      method: 'POST',
      path: '/v1/ratelimit.commitLease',
      body,
    });

    if (response.status === 204) {
      return; // No Content
    }

    if (response.status === 400) {
      const errorData: types.ValidationError = await response.json();
      throw new ExampleError(errorData.detail, {
        status: errorData.status,
        data: errorData,
      });
    }

    if (response.status === 500) {
      const errorData: types.BaseError = await response.json();
      throw new ExampleError(errorData.detail, {
        status: errorData.status,
        data: errorData,
      });
    }

    throw new Error('Unexpected response');
  }
}

// Type definitions for the new method
export interface CommitLeaseResponse {
  // No response body expected for 204
}
```

This code snippet adds the `commitLease` method to the `ExampleClient` class, handling the specified OpenAPI route with appropriate type definitions and error handling.