> ## 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.

# Create Policy

> Create a policy. Use it with `model: "auto/<policyId>"`. At most 50 policies.



## OpenAPI

````yaml POST /router/policies
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:
    post:
      tags:
        - Router
      summary: Create policy
      description: >-
        Create a policy. Use it with `model: "auto/<policyId>"`. At most 50
        policies.
      operationId: createRouterPolicy
      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:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RouterPolicyEnvelope'
              example:
                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: 1
                warnings: []
        '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: A policy with this id exists
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  message: A policy with this id already exists
                  type: router_conflict
                  param: null
                  code: 409
        '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
    RouterPolicyEnvelope:
      type: object
      properties:
        policy:
          $ref: '#/components/schemas/RouterPolicy'
        version:
          type: integer
        updatedAt:
          type: string
          format: date-time
          nullable: true
        updatedBy:
          type: string
        warnings:
          type: array
          items:
            type: string
    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.