> ## Documentation Index
> Fetch the complete documentation index at: https://docs.inkwell.finance/llms.txt
> Use this file to discover all available pages before exploring further.

# Compute rebalance plan

> Given current staking positions, computes the optimal rebalance steps (unstake from underperformers, stake to better validators).
**Requires builder or pro tier.**




## OpenAPI

````yaml /openapi/leviathan.yaml post /api/v1/ika/agent/rebalance-plan
openapi: 3.1.0
info:
  title: Inkwell Agent API
  version: 0.1.0
  description: >
    REST API for AI agents to interact with IKA staking infrastructure and
    Leviathan protocol services.


    ## Authentication


    Most endpoints require an API key passed via the `X-API-Key` header.

    Register at `POST /api/v1/agents/self-register` to obtain a free-tier key.


    ## Rate Limits


    | Tier     | RPM | RPD    |

    |----------|-----|--------|

    | free     | 10  | 100    |

    | builder  | 100 | 1,000  |

    | pro      | custom | custom |


    Rate limit headers (`X-RateLimit-Remaining-RPM`,
    `X-RateLimit-Remaining-RPD`) are included on every authenticated response.
  contact:
    name: Inkwell Finance
    email: support@inkwell.finance
    url: https://inkwell.finance
  license:
    name: MIT
servers:
  - url: https://backend.inkwell.finance
    description: Production
  - url: http://localhost:3000
    description: Local development
security:
  - ApiKeyAuth: []
tags:
  - name: IKA Staking (Agent)
    description: >-
      Authenticated endpoints for staking allocation, transaction building, and
      rebalancing. Requires API key.
  - name: IKA Staking (Public)
    description: >-
      Public read-only endpoints for validator data, pricing, and APY history.
      No auth required.
  - name: Agent Identity
    description: Register API keys, manage agents, rotate credentials.
paths:
  /api/v1/ika/agent/rebalance-plan:
    post:
      tags:
        - IKA Staking (Agent)
      summary: Compute rebalance plan
      description: >
        Given current staking positions, computes the optimal rebalance steps
        (unstake from underperformers, stake to better validators).

        **Requires builder or pro tier.**
      operationId: ikaAgentRebalancePlan
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RebalanceRequest'
      responses:
        '200':
          description: Rebalance plan with steps
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RebalancePlanResponse'
        '400':
          $ref: '#/components/responses/ValidationError'
        '403':
          description: Tier too low (requires builder or pro)
components:
  schemas:
    RebalanceRequest:
      type: object
      required:
        - positions
      properties:
        positions:
          type: array
          minItems: 1
          maxItems: 50
          items:
            type: object
            required:
              - stakedIkaId
              - validatorId
              - principal
            properties:
              stakedIkaId:
                type: string
              validatorId:
                type: string
              principal:
                type: string
        maxTargets:
          type: integer
          minimum: 1
          maximum: 10
          default: 10
    RebalancePlanResponse:
      type: object
      properties:
        currentPositions:
          type: array
          items:
            type: object
            properties:
              validator:
                type: string
              stakedAmount:
                type: string
              currentApy:
                type: number
        steps:
          type: array
          items:
            type: object
            properties:
              action:
                type: string
                enum:
                  - unstake
                  - stake
              validator:
                type: string
              amount:
                type: string
              requiresEpochWait:
                type: boolean
              order:
                type: integer
        summary:
          type: object
          properties:
            currentWeightedApy:
              type: number
            projectedWeightedApy:
              type: number
            estimatedEpochsToComplete:
              type: integer
        dataAgeSeconds:
          type: number
  responses:
    ValidationError:
      description: Invalid input
      content:
        application/json:
          schema:
            type: object
            properties:
              error:
                type: string
              message:
                type: string
              status:
                type: integer
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key
      description: Agent API key obtained via self-registration or admin registration

````