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

> ## Agent Instructions
> These are the Ampli Intelligence docs. API base: https://si.ampli.net/api/v1. API MCP: https://si.ampli.net/mcp.
> Auth is a partner key (X-Partner-Name and X-Partner-API-Key headers) or an x402 payment in USDC on Base.
> For a single-treasury agentic wallet or Wallet-as-a-Service, use the ampli^ SDK at https://ampli.net and https://docs.ampli.net. agk_ keys and /api/v1/agent-runtime belong to that SDK.
> Use only the routes and tools documented here. Do not invent endpoints or parameters.
> The ampli^ SDK (https://ampli.net, docs at https://docs.ampli.net) can use this intelligence to deliver a single-treasury agentic wallet or Wallet-as-a-Service. This host is si.ampli.net. Auth is a partner key or an x402 payment. agk_ keys and /api/v1/agent-runtime belong to the SDK Agent API.
> Every amount is an integer string in the token's base units. USDC, EURC, USDT0, and USDG use 6 decimals (1000000 is 1 USDC). WETH and cbETH use 18. cbBTC uses 8.
> The service is non-custodial. It returns an allocation, an action plan, and calldata. It never holds keys, signs, or sends a transaction.
> APR values are percentages measured now or over the trailing 7 days. They are not forecasts and nothing here guarantees a return.
> x402 payments are verified before the work and settled only when the response is 2xx. A 400 or 422 costs nothing.
> Partner headers always win. A request with a wrong partner key returns 401 and does not fall back to payment.
> Monitor alerts arrive only on the websocket. create_monitor_session returns a token; the client must open the socket itself.
> Market names in optimize must come from list_protocols for the same chain and token. Do not guess names.

# Optimize Allocations

> Send X-Partner-Name and X-Partner-API-Key, or pay with x402: without partner headers the route answers 402 with a PAYMENT-REQUIRED header; retry with PAYMENT-SIGNATURE. Payment settles only on a 2xx and the receipt is returned in PAYMENT-RESPONSE.



## OpenAPI

````yaml /openapi.json post /api/v1/optimizer/{chain_id}/optimize
openapi: 3.1.0
info:
  title: Ampli Intelligence API
  version: 0.1.0
  description: >-
    Non-custodial lending allocation plans, market data, and health checks.
    Authenticate with partner headers or pay per call with x402. The ampli^ SDK
    (https://ampli.net, https://docs.ampli.net) can use this API to deliver a
    single-treasury agentic wallet or Wallet-as-a-Service.
servers:
  - url: https://si.ampli.net
security:
  - partnerName: []
    partnerKey: []
paths:
  /api/v1/optimizer/{chain_id}/optimize:
    post:
      tags:
        - Optimizer
      summary: Optimize Allocations
      description: >-
        Send X-Partner-Name and X-Partner-API-Key, or pay with x402: without
        partner headers the route answers 402 with a PAYMENT-REQUIRED header;
        retry with PAYMENT-SIGNATURE. Payment settles only on a 2xx and the
        receipt is returned in PAYMENT-RESPONSE.
      operationId: optimize_allocations_api_v1_optimizer__chain_id__optimize_post
      parameters:
        - name: chain_id
          in: path
          required: true
          schema:
            type: integer
            title: Chain Id
        - name: X-Partner-API-Key
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: X-Partner-Api-Key
        - name: X-Partner-Name
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: X-Partner-Name
        - name: PAYMENT-SIGNATURE
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: Payment-Signature
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/OptimizeRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OptimizeResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    OptimizeRequest:
      properties:
        total_capital:
          type: string
          title: Total Capital
          description: Total amount to allocate (bigint as string)
          examples:
            - '1000000000'
        token_address:
          type: string
          title: Token Address
          description: Token address to optimize for
        current_allocations:
          additionalProperties:
            type: string
          type: object
          title: Current Allocations
          description: >-
            Current holdings mapping protocol names to amounts (bigint as
            string)
        protocols:
          items:
            type: string
          type: array
          title: Protocols
          description: Protocol names to consider
        constraints:
          anyOf:
            - items:
                $ref: '#/components/schemas/ConstraintSchema'
              type: array
            - type: 'null'
          title: Constraints
        wallet_address:
          anyOf:
            - type: string
            - type: 'null'
          title: Wallet Address
          description: Wallet address that will execute the transactions
      type: object
      required:
        - total_capital
        - token_address
        - current_allocations
        - protocols
      title: OptimizeRequest
    OptimizeResponse:
      properties:
        optimization_result:
          $ref: '#/components/schemas/OptimizationResult'
        action_plan:
          items:
            $ref: '#/components/schemas/ActionDetail'
          type: array
          title: Action Plan
        calldata:
          items:
            $ref: '#/components/schemas/CalldataInfo'
          type: array
          title: Calldata
        market_rules:
          items:
            $ref: '#/components/schemas/MarketRule'
          type: array
          title: Market Rules
          description: >-
            How each requested market was rated before the solver ran: closed,
            capped, or APR discounted.
      type: object
      required:
        - optimization_result
        - action_plan
        - calldata
      title: OptimizeResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ConstraintSchema:
      properties:
        kind:
          $ref: '#/components/schemas/WalletConstraints'
        params:
          additionalProperties: true
          type: object
          title: Params
      type: object
      required:
        - kind
        - params
      title: ConstraintSchema
    OptimizationResult:
      properties:
        allocations:
          items:
            $ref: '#/components/schemas/ProtocolAllocation'
          type: array
          title: Allocations
        total_costs:
          type: number
          title: Total Costs
          description: >-
            Gas for the action plan, in the token's base units (the same unit as
            total_capital). Divide by 10**decimals before comparing with
            gas_estimate_usd.
        weighted_apr_initial:
          type: number
          title: Weighted Apr Initial
        weighted_apr_final:
          type: number
          title: Weighted Apr Final
        apr_improvement:
          type: number
          title: Apr Improvement
        gas_estimate_usd:
          anyOf:
            - type: number
            - type: 'null'
          title: Gas Estimate Usd
          description: >-
            total_costs converted to USD: (total_costs / 10**decimals) * token
            price.
        break_even_days:
          anyOf:
            - type: number
            - type: 'null'
          title: Break Even Days
      type: object
      required:
        - allocations
        - total_costs
        - weighted_apr_initial
        - weighted_apr_final
        - apr_improvement
      title: OptimizationResult
    ActionDetail:
      properties:
        action_type:
          type: string
          title: Action Type
        protocol:
          type: string
          title: Protocol
        amount:
          type: string
          title: Amount
        underlying_amount:
          anyOf:
            - type: string
            - type: 'null'
          title: Underlying Amount
      type: object
      required:
        - action_type
        - protocol
        - amount
      title: ActionDetail
    CalldataInfo:
      properties:
        contract_address:
          type: string
          title: Contract Address
        function_name:
          type: string
          title: Function Name
        parameters:
          items:
            type: string
          type: array
          title: Parameters
        value:
          type: string
          title: Value
          default: '0'
        protocol:
          type: string
          title: Protocol
        description:
          type: string
          title: Description
      type: object
      required:
        - contract_address
        - function_name
        - parameters
        - protocol
        - description
      title: CalldataInfo
    MarketRule:
      properties:
        protocol:
          type: string
          title: Protocol
        eligible:
          type: boolean
          title: Eligible
          description: False when the market is closed to new deposits in this run.
        max_allocation:
          anyOf:
            - type: string
            - type: 'null'
          title: Max Allocation
          description: >-
            Largest total this market may hold, in base units. None when no rule
            caps it below total_capital.
        apr_scale:
          anyOf:
            - type: number
            - type: 'null'
          title: Apr Scale
          description: >-
            Multiplier on the APR curve when the latest APR is above its
            trailing mean.
        reasons:
          items:
            type: string
          type: array
          title: Reasons
          description: The health and liquidity rules that applied.
      type: object
      required:
        - protocol
        - eligible
      title: MarketRule
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    WalletConstraints:
      type: string
      enum:
        - min_protocols
        - max_allocation_amount_per_protocol
        - max_amount_per_protocol
        - min_amount
        - exclude_protocol
        - min_allocation_amount_per_protocol
      title: WalletConstraints
    ProtocolAllocation:
      properties:
        protocol:
          type: string
          title: Protocol
        allocation:
          type: string
          title: Allocation
        apr:
          type: number
          title: Apr
      type: object
      required:
        - protocol
        - allocation
        - apr
      title: ProtocolAllocation
  securitySchemes:
    partnerName:
      type: apiKey
      in: header
      name: X-Partner-Name
    partnerKey:
      type: apiKey
      in: header
      name: X-Partner-API-Key

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.