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

# Import Policy

> Save an exported policy under `policy_id`. Returns the changes from the stored version in `diff`.



## OpenAPI

````yaml POST /router/policies/{policy_id}/import
openapi: 3.0.1
info:
  title: Electron Hub API
  description: >-
    Unified API platform integrating 200+ AI models for chat, image generation,
    speech-to-text, embeddings, and more.
  version: 1.0.0
  contact:
    name: Electron Hub Support
    email: support@electronhub.ai
    url: https://discord.com/invite/electronhub
  license:
    name: MIT
servers:
  - url: https://api.electronhub.ai/v1
    description: Production API v1
security:
  - bearerAuth: []
paths:
  /router/policies/{policy_id}/import:
    post:
      tags:
        - Router
      summary: Import policy
      description: >-
        Save an exported policy under `policy_id`. Returns the changes from the
        stored version in `diff`.
      operationId: importRouterPolicy
      parameters:
        - name: policy_id
          in: path
          required: true
          schema:
            type: string
            pattern: ^[a-z0-9-]{1,40}$
          example: work
        - name: expected_version
          in: query
          required: false
          schema:
            type: integer
          description: >-
            Fail with 409 when the stored version differs. Can also be sent in
            the body.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RouterPolicy'
            example:
              policyId: work
              name: Work
              mode: auto
              auto:
                costTier: high
              models:
                excluded:
                  - '*:free'
              guardrails:
                budgetUsd: 5
                budgetWindow: daily
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RouterPolicyValidation'
              example:
                ok: true
                errors: []
                warnings: []
                policy:
                  policyId: imported
                  name: Work
                  schemaVersion: 4
                  mode: auto
                  auto:
                    costTier: high
                    qualityFloor: 0
                    preferFast: false
                    preferVendor: null
                    preferStrength: 0
                    maxTtft: 0
                    perCategory: {}
                  custom:
                    rules: []
                    default:
                      - action: useAuto
                  models:
                    allowed: []
                    excluded:
                      - '*:free'
                    strictAllowed: false
                  guardrails:
                    maxCostPerReq: null
                    blockOverCost: false
                    budgetUsd: 5
                    budgetWindow: daily
                    budgetScope: routed
                    blockOverBudget: false
                    pii:
                      enabled: false
                      action: block
                      model: null
                      entities: {}
                      labels: {}
                      custom: []
                      scanAll: false
                  cache:
                    enabled: false
                    ttlMin: 1440
                    maxEntries: 100
                    semantic: false
                    semanticThreshold: 0.9
                migrated: false
                diff:
                  - label: Cost tier
                    from: medium
                    to: high
                  - label: Excluded models
                    from: 0
                    to: 1
                  - label: Budget
                    from: null
                    to: 5
                version: 1
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  message: Body must be an object.
                  type: invalid_request_error
                  param: null
                  code: 400
        '403':
          description: Proxy keys cannot manage Router settings
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  message: Only master keys can manage Router settings.
                  type: error
                  param: null
                  code: 403
        '409':
          description: Version conflict. `current` holds the stored document.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  message: Version conflict
                  type: router_conflict
                  param: null
                  code: 409
                current:
                  policy:
                    policyId: work
                    name: Work
                    schemaVersion: 4
                    mode: auto
                    auto:
                      costTier: high
                      qualityFloor: 0
                      preferFast: false
                      preferVendor: null
                      preferStrength: 0
                      maxTtft: 0
                      perCategory: {}
                    custom:
                      rules: []
                      default:
                        - action: useAuto
                    models:
                      allowed: []
                      excluded:
                        - '*:free'
                      strictAllowed: false
                    guardrails:
                      maxCostPerReq: null
                      blockOverCost: false
                      budgetUsd: 5
                      budgetWindow: daily
                      budgetScope: routed
                      blockOverBudget: false
                      pii:
                        enabled: false
                        action: block
                        model: null
                        entities: {}
                        labels: {}
                        custom: []
                        scanAll: false
                    cache:
                      enabled: false
                      ttlMin: 1440
                      maxEntries: 100
                      semantic: false
                      semanticThreshold: 0.9
                  version: 4
                  updatedAt: '2026-11-08T07:34:14.937184Z'
                  updatedBy: client
        '429':
          description: More than 60 Router writes in a minute
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  message: Too many Router changes. Retry in a minute.
                  type: rate_limit_exceeded
                  param: null
                  code: 429
components:
  schemas:
    RouterPolicy:
      type: object
      description: >-
        Missing fields take defaults. See
        https://docs.electronhub.ai/routing/auto-router#policies
      properties:
        policyId:
          type: string
          pattern: ^[a-z0-9-]{1,40}$
        name:
          type: string
        schemaVersion:
          type: integer
          example: 4
        mode:
          type: string
          enum:
            - auto
            - custom
          description: '`custom` evaluates `custom.rules` first.'
        auto:
          type: object
          properties:
            costTier:
              type: string
              enum:
                - low
                - medium
                - high
                - xhigh
                - max
              default: medium
            qualityFloor:
              type: number
              minimum: 0
              maximum: 100
              description: Minimum benchmark score (0 = off).
            preferFast:
              type: boolean
              description: Prefer models with the fastest end-to-end response.
            preferVendor:
              type: string
              nullable: true
              description: Vendor to favour, e.g. `Anthropic`.
            preferStrength:
              type: number
              minimum: 0
              maximum: 0.2
              description: How strongly to favour `preferVendor`.
            maxTtft:
              type: number
              minimum: 0
              description: Maximum seconds to the first answer token (0 = off).
            perCategory:
              type: object
              additionalProperties:
                type: string
              description: >-
                Fixed model per category, e.g. `{"coding":
                "claude-sonnet-5-5"}`.
        custom:
          type: object
          properties:
            rules:
              type: array
              items:
                type: object
              description: >-
                Ordered rules: `when` conditions on request signals, `then`
                actions.
            default:
              type: array
              items:
                type: object
              description: 'Actions when no rule matches. Default `[{"action": "useAuto"}]`.'
        models:
          type: object
          properties:
            allowed:
              type: array
              items:
                type: string
              description: Model patterns, e.g. `anthropic/*`.
            excluded:
              type: array
              items:
                type: string
            strictAllowed:
              type: boolean
              description: Fail with 404 when `allowed` matches nothing.
        guardrails:
          type: object
          properties:
            maxCostPerReq:
              type: number
              nullable: true
              description: Estimated cost cap per request, in USD.
            blockOverCost:
              type: boolean
              description: Block instead of downgrading when over `maxCostPerReq`.
            budgetUsd:
              type: number
              nullable: true
              description: Spend budget per window, in USD.
            budgetWindow:
              type: string
              enum:
                - daily
                - weekly
                - monthly
              description: Windows start at 00:00 UTC.
            budgetScope:
              type: string
              enum:
                - routed
                - all
              description: Count Auto requests only, or all spend.
            blockOverBudget:
              type: boolean
              description: >-
                Block instead of using the cheapest model when the budget is
                spent.
            pii:
              type: object
              description: Privacy guard.
              properties:
                enabled:
                  type: boolean
                action:
                  type: string
                  enum:
                    - block
                    - redact
                    - route
                model:
                  type: string
                  nullable: true
                  description: 'Model for `action: route`.'
                entities:
                  type: object
                  additionalProperties:
                    type: boolean
                  description: Entity types to detect; empty means all except `name`.
                scanAll:
                  type: boolean
                  description: Scan every message, not only the latest.
        cache:
          type: object
          description: Response cache for repeated requests.
          properties:
            enabled:
              type: boolean
            ttlMin:
              type: integer
              minimum: 1
              maximum: 43200
            maxEntries:
              type: integer
              minimum: 1
              maximum: 5000
            semantic:
              type: boolean
              description: Also match similar, not only identical, requests.
            semanticThreshold:
              type: number
              minimum: 0.8
              maximum: 0.99
    RouterPolicyValidation:
      type: object
      properties:
        ok:
          type: boolean
        errors:
          type: array
          items:
            type: string
        warnings:
          type: array
          items:
            type: string
        policy:
          allOf:
            - $ref: '#/components/schemas/RouterPolicy'
          nullable: true
        migrated:
          type: boolean
        diff:
          type: array
          items:
            type: object
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - message
            - type
          properties:
            message:
              type: string
            type:
              type: string
            code:
              type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: Enter your API key (starts with 'ek-')

````

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