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

> ## Agent Instructions
> Phaseo Gateway base URL: https://api.phaseo.app/v1. Send `Authorization: Bearer $PHASEO_API_KEY` with every request.
> Model IDs look like `provider/model`, for example `openai/gpt-6-astra`. Do not guess IDs: list them with `GET /v1/models` or check https://phaseo.app/models. `phaseo/free` routes to an available free model and needs no wallet balance.
> For new text integrations prefer `POST /v1/responses`. `POST /v1/chat/completions` (OpenAI format) and `POST /v1/messages` (Anthropic format) suit existing code.
> The full API contract is https://phaseo.app/docs/openapi/v1/openapi.yaml. Official SDKs: `@phaseo/sdk` (TypeScript) and `phaseo` (Python), plus Go, C#, PHP, Ruby and Rust.
> Search these docs over MCP at https://phaseo.app/docs/mcp, and install Phaseo skills with `npx skills add https://phaseo.app/docs`. If a page is wrong or out of date, report it with the MCP `submit_feedback` tool.
> Manage Phaseo accounts with the `phaseo` CLI (`npm install -g @phaseo/cli`, then `phaseo login` or `phaseo login --device-code`), the `/v1` Management API or the MCP server at `https://mcp.phaseo.app/mcp?access=manage`. Do not send users to the dashboard for account tasks. A person is still needed for sign-up, approving a sign-in, paying the first top-up on the checkout link that `phaseo credits add` returns when no card is saved, confirming each saved-card top-up from the emailed link, and account security (password, MFA, passkeys). Create API keys with `phaseo keys create --name <name> --json`; never guess one. Credit top-ups need `phaseo login --scopes billing:write` first. Task map: https://phaseo.app/docs/v1/developers/manage-from-an-agent.md.

# معاينة قاعدة إنفاق

> يعرض القيمة الحالية لقاعدة الإنفاق وأساسها والحد التالي.

يتطلب `spend_rules:read`. لا يُرسل أي شيء ولا يُسجَّل. تتضمن قواعد التوقع والارتفاع المفاجئ والرصيد كائنها الخاص `forecast` أو `spike` أو `balance`.


## OpenAPI

````yaml ar/openapi/v1/openapi.localized.yaml GET /spend-rules/{id}/preview
openapi: 3.0.3
info:
  title: Phaseo Gateway API
  description: >-
    واجهة API للبوابة تتيح الوصول إلى نماذج ذكاء اصطناعي متنوعة عبر نقاط نهاية
    متوافقة مع OpenAI.
  version: 1.0.0
  contact:
    name: Phaseo
    url: https://phaseo.app
    email: danielbutler500@gmail.com
servers:
  - url: https://api.phaseo.app/v1
    description: التوجيه العالمي
security:
  - BearerAuth: []
tags:
  - name: Gateway
    description: Core Phaseo Gateway operations.
paths:
  /spend-rules/{id}/preview:
    parameters:
      - name: id
        in: path
        required: true
        description: معرّف قاعدة الإنفاق.
        schema:
          type: string
          format: uuid
    get:
      tags:
        - Gateway
      summary: معاينة قاعدة إنفاق
      description: >-
        يعيد الفترة الحالية للقاعدة والإنفاق حتى الآن والأساس والنسبة المئوية
        والحد التالي، محسوبةً كما في التقييم، دون إرسال أو تسجيل أي شيء.
      operationId: previewSpendRule
      responses:
        '200':
          description: معاينة قاعدة الإنفاق
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SpendRulePreviewResponse'
        default:
          description: فشل الطلب
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    SpendRulePreviewResponse:
      type: object
      required:
        - data
      properties:
        data:
          $ref: '#/components/schemas/SpendRulePreview'
    ErrorResponse:
      type: object
      required:
        - error
      properties:
        ok:
          type: boolean
          example: false
        error:
          description: >-
            كائن الخطأ (`code` و`message` و`type` و`param` و`metadata`
            الاختياري) الذي تقرؤه حزم SDK المتوافقة مع OpenAI. كانت الاستجابات
            السابقة تُرجع سلسلة الرمز هنا؛ وهي تُرجع الآن أيضًا في `code` على
            المستوى الأعلى.
          oneOf:
            - type: string
            - $ref: '#/components/schemas/ErrorObject'
          example:
            code: validation_error
            message: 'Unknown parameter: foo'
            type: invalid_request_error
            param: foo
        code:
          type: string
          description: رمز الخطأ، بالقيمة نفسها الموجودة في `error.code`.
          example: validation_error
        message:
          type: string
          example: Human-readable error message
        description:
          type: string
          example: Additional error details.
        generation_id:
          type: string
          example: G-abc123
        status_code:
          type: integer
          example: 502
        error_type:
          type: string
          enum:
            - user
            - system
          example: system
        error_origin:
          type: string
          enum:
            - user
            - gateway
            - upstream
          example: upstream
        reason:
          type: string
          example: all_candidates_failed
        attempt_count:
          type: integer
          example: 2
        failed_providers:
          type: array
          items:
            type: string
          example:
            - google-ai-studio
            - openai
        failed_statuses:
          type: array
          items:
            type: integer
          example:
            - 403
            - 429
        upstream_error:
          $ref: '#/components/schemas/ErrorUpstreamError'
        failure_sample:
          type: array
          items:
            $ref: '#/components/schemas/ErrorFailureSampleItem'
        provider_failure_diagnostics:
          $ref: '#/components/schemas/ErrorProviderFailureDiagnostics'
        routing_diagnostics:
          $ref: '#/components/schemas/ErrorRoutingDiagnostics'
        provider_candidate_diagnostics:
          $ref: '#/components/schemas/ErrorProviderCandidateDiagnostics'
        provider_enablement:
          $ref: '#/components/schemas/ErrorProviderEnablementDiagnostics'
        missing_pricing_providers:
          type: array
          items:
            type: string
        provider_payment_required_provider:
          type: string
          example: openai
        provider_payment_required_support_notice:
          type: string
          example: >-
            Our upstream provider billing appears to be unavailable. If this
            persists, contact support.
        details:
          type: array
          items:
            type: object
            additionalProperties: true
      additionalProperties: true
    SpendRulePreview:
      type: object
      description: >-
        وضع قاعدة الإنفاق الآن. تكون لقواعد rolling نافذتها بصفتها period. تحتوي
        قواعد forecast على كائن forecast، وتُقاس عتباتها على التوقع. تكون لقواعد
        balance نافذة معدل الاستهلاك بصفتها period، والرصيد المتاح بصفته القيمة،
        وكائن balance. وتكون لقواعد spike نافذتها بصفتها period، والإنفاق خلالها
        بصفته القيمة، ووسيط النافذة نفسها خلال الأيام السبعة السابقة بصفته
        الأساس، ونقطة التنبيه بصفتها next_threshold، وكائن spike.
      required:
        - rule_id
        - metric
        - evaluated
        - computed_at
        - time_zone
        - period
        - value_nanos
        - value_usd
        - base_kind
        - base_ref
        - base_nanos
        - base_usd
        - previous_period
        - forecast
        - percent
        - threshold_percents
        - threshold_amount_nanos
        - threshold_amount_usd
        - reached_threshold_percent
        - next_threshold
        - block_at_nanos
        - block_at_usd
        - balance
        - spike
        - state
        - alert
      properties:
        rule_id:
          type: string
          format: uuid
        metric:
          $ref: '#/components/schemas/SpendRuleMetric'
        evaluated:
          type: boolean
          description: >-
            ما إذا كان التقييم يدعم مقياس القاعدة وفترتها وأساسها. تُقيَّم كل
            القواعد التي تقبلها الواجهة البرمجية.
        computed_at:
          type: string
          format: date-time
        time_zone:
          type: string
        period:
          type: object
          nullable: true
          required:
            - kind
            - start
            - end
          properties:
            kind:
              $ref: '#/components/schemas/SpendRulePeriod'
            start:
              type: string
              format: date-time
            end:
              type: string
              format: date-time
            window_hours:
              type: integer
              description: 'قواعد rolling فقط: طول النافذة بالساعات.'
        value_nanos:
          type: integer
          format: int64
          nullable: true
        value_usd:
          type: number
          nullable: true
        base_kind:
          type: string
          enum:
            - amount
            - workspace_budget
            - key_limit
            - previous_period
          nullable: true
        base_ref:
          type: string
          nullable: true
          enum:
            - daily
            - weekly
            - monthly
        base_nanos:
          type: integer
          format: int64
          nullable: true
        base_usd:
          type: number
          nullable: true
        previous_period:
          type: object
          nullable: true
          description: >-
            أسس previous_period فقط: الجزء من الفترة السابقة الذي يغطيه الأساس
            (النقطة نفسها في الفترة السابقة، أو النافذة السابقة لقاعدة rolling،
            أو الفترة السابقة كاملة في حالة forecast). تكون null للأسس الأخرى.
          required:
            - start
            - end
          properties:
            start:
              type: string
              format: date-time
            end:
              type: string
              format: date-time
        forecast:
          type: object
          nullable: true
          description: >-
            قواعد forecast فقط: الإنفاق في نهاية الفترة إذا استمر المعدل الحالي
            (خط مستقيم من بداية الفترة، كما تتوقعه لوحة الاستخدام). تكون null
            للقواعد الأخرى.
          required:
            - ready
            - from
            - projected_nanos
            - projected_usd
            - projected_percent
            - by
            - limit_nanos
            - limit_usd
            - reaches_at
          properties:
            ready:
              type: boolean
              description: >-
                تكون false إلى أن يمر جزء كافٍ من الفترة لإجراء التوقع: 3 ساعات
                من اليوم، أو 24 ساعة من الأسبوع، أو 72 ساعة من الشهر.
            from:
              type: string
              format: date-time
              nullable: true
              description: متى يبدأ التوقع.
            projected_nanos:
              type: integer
              format: int64
              nullable: true
            projected_usd:
              type: number
              nullable: true
            projected_percent:
              type: number
              nullable: true
              description: التوقع كنسبة مئوية من الأساس.
            by:
              type: string
              format: date-time
              description: نهاية الفترة التي يخصها التوقع.
            limit_nanos:
              type: integer
              format: int64
              nullable: true
              description: 'ما يُقاس به التوقع: عتبة المبلغ، وإلا فالأساس.'
            limit_usd:
              type: number
              nullable: true
            reaches_at:
              type: string
              format: date-time
              nullable: true
              description: متى يصل المعدل الحالي إلى الحد، إذا حدث ذلك قبل انتهاء الفترة.
        percent:
          type: number
          nullable: true
        threshold_percents:
          type: array
          items:
            type: integer
          nullable: true
        threshold_amount_nanos:
          type: integer
          format: int64
          nullable: true
        threshold_amount_usd:
          type: number
          nullable: true
        reached_threshold_percent:
          type: integer
          nullable: true
        next_threshold:
          type: object
          nullable: true
          description: >-
            الحد التالي الذي لم تبلغه القيمة بعد: نسبة مئوية من الأساس (null
            لحدود المبالغ) ومبلغه.
          required:
            - percent
            - amount_nanos
            - amount_usd
          properties:
            percent:
              type: integer
              nullable: true
            amount_nanos:
              type: integer
              format: int64
            amount_usd:
              type: number
        block_at_nanos:
          type: integer
          format: int64
          nullable: true
        block_at_usd:
          type: number
          nullable: true
        state:
          type: object
          nullable: true
          required:
            - highest_percent_fired
            - amount_fired_at
            - last_fired_at
            - fire_count
          properties:
            highest_percent_fired:
              type: integer
              nullable: true
            amount_fired_at:
              type: string
              format: date-time
              nullable: true
            last_fired_at:
              type: string
              format: date-time
              nullable: true
            fire_count:
              type: integer
            armed:
              type: boolean
              description: 'قواعد balance: تكون false بعد التنبيه حتى يعود الرصيد فوق الحد.'
        balance:
          type: object
          nullable: true
          description: >-
            لقواعد balance فقط: وضع الرصيد كما يراه التقييم. تكون null للقواعد
            الأخرى.
          required:
            - balance_usd
            - reserved_usd
            - available_nanos
            - available_usd
            - window_hours
            - burn_usd
            - burn_per_day_usd
            - runway_days_left
            - low_balance
            - low_runway
            - armed
            - auto_top_up_covers
          properties:
            balance_usd:
              type: number
            reserved_usd:
              type: number
            available_nanos:
              type: integer
              format: int64
              description: >-
                الرصيد مطروحًا منه الرصيد المحجوز: وهو ما تُقبل الطلبات على
                أساسه.
            available_usd:
              type: number
            window_hours:
              type: integer
            burn_usd:
              type: number
            burn_per_day_usd:
              type: number
            runway_days_left:
              type: number
              nullable: true
              description: >-
                عدد الأيام التي يكفيها الرصيد المتاح بمعدل الاستهلاك. تكون null
                عند عدم وجود إنفاق في النافذة.
            low_balance:
              type: boolean
            low_runway:
              type: boolean
            armed:
              type: boolean
            auto_top_up_covers:
              type: boolean
              description: الشحن التلقائي مفعّل ويعمل، لذا يُسجَّل الانخفاض دون تنبيه.
        spike:
          type: object
          nullable: true
          description: >-
            قواعد spike فقط: الإنفاق خلال آخر window_hours مقارنةً بوسيط النافذة
            نفسها خلال الأيام السبعة السابقة، كما يراه التقييم. تكون null
            للقواعد الأخرى.
          required:
            - window_hours
            - current_nanos
            - current_usd
            - baseline_nanos
            - baseline_usd
            - multiple
            - multiplier
            - floor_usd
            - fires_at_nanos
            - fires_at_usd
            - baseline_windows
            - active_windows
            - history_ready
            - spiking
            - cooldown_until
          properties:
            window_hours:
              type: integer
            current_nanos:
              type: integer
              format: int64
            current_usd:
              type: number
            baseline_nanos:
              type: integer
              format: int64
              description: >-
                وسيط النافذة نفسها خلال الأيام السبعة السابقة: الساعات نفسها في
                كل يوم من الأيام السبعة السابقة للنوافذ الأقل من 24 ساعة، وإلا
                فالنوافذ السابقة غير المتداخلة التي تتسع لها 7 أيام.
            baseline_usd:
              type: number
            multiple:
              type: number
              nullable: true
              description: >-
                الإنفاق خلال النافذة مقسومًا على الأساس. تكون null عندما يكون
                الأساس 0، وعندها يُطبَّق الحد الأدنى وحده.
            multiplier:
              type: number
            floor_usd:
              type: number
            fires_at_nanos:
              type: integer
              format: int64
              description: >-
                ما يجب أن يبلغه الإنفاق خلال النافذة لإطلاق التنبيه: الأكبر بين
                spike_multiplier مرة من الأساس والحد الأدنى.
            fires_at_usd:
              type: number
            baseline_windows:
              type: integer
              description: عدد النوافذ في الأساس. تحتاج القاعدة إلى 3 على الأقل.
            active_windows:
              type: integer
              description: نوافذ الأساس التي أنفقت فيها مساحة العمل أي مبلغ.
            history_ready:
              type: boolean
              description: >-
                تكون false إلى أن تنفق مساحة العمل في 3 نوافذ أساس على الأقل. لا
                تُطلق القاعدة تنبيهًا قبل ذلك.
            spiking:
              type: boolean
              description: >-
                ما إذا كانت القاعدة ستُطلق تنبيهًا الآن، قبل احتساب فترة
                التهدئة.
            cooldown_until:
              type: string
              format: date-time
              nullable: true
              description: متى تنتهي فترة التهدئة بعد آخر تنبيه، إن لم تكن قد انتهت بعد.
        alert:
          type: object
          nullable: true
          description: >-
            النص الذي سيحمله التنبيه الآن، مع ذكر أعلى حد تم بلوغه، أو الحد
            الأول.
          required:
            - scope_label
            - title
            - message
          properties:
            scope_label:
              type: string
            title:
              type: string
            message:
              type: string
    ErrorObject:
      type: object
      description: >-
        خطأ من البوابة بالشكل الذي تقرؤه حزم SDK من OpenAI. يُحدَّد `type` من
        حالة HTTP: invalid_request_error لمعظم رموز 4xx، وauthentication_error
        (401)، وinsufficient_quota (402)، وpermission_error (403)،
        وnot_found_error (404)، وrate_limit_error (429)، وservice_unavailable
        (503)، وoverloaded (529)، وserver_error لبقية رموز 5xx.
      required:
        - code
        - message
        - type
      properties:
        code:
          type: string
          description: رمز خطأ قابل للقراءة آليًا.
          example: validation_error
        message:
          type: string
          description: شرح مقروء لسبب الإخفاق.
          example: 'Unknown parameter: foo'
        type:
          type: string
          description: نوع الخطأ، وفق أنواع الأخطاء الموثّقة لدى OpenAI.
          enum:
            - invalid_request_error
            - authentication_error
            - permission_error
            - not_found_error
            - rate_limit_error
            - insufficient_quota
            - server_error
            - service_unavailable
            - overloaded
          example: invalid_request_error
        param:
          type: string
          nullable: true
          description: معامل الطلب الذي تسبّب في الخطأ، عند معرفته.
          example: foo
        metadata:
          type: object
          description: >-
            تفاصيل منظّمة تُرجع أيضًا على المستوى الأعلى، مثل المزوّد الذي أخفق
            و`reason` و`failed_statuses` و`retry_after_seconds`
            و`upstream_error`.
          additionalProperties: true
      additionalProperties: true
    ErrorUpstreamError:
      type: object
      properties:
        code:
          type: string
          nullable: true
          example: PERMISSION_DENIED
        message:
          type: string
          nullable: true
          example: The caller does not have permission.
        description:
          type: string
          nullable: true
        param:
          type: string
          nullable: true
    ErrorFailureSampleItem:
      type: object
      properties:
        provider:
          type: string
          nullable: true
        type:
          type: string
          nullable: true
        status:
          type: integer
          nullable: true
        upstream_error_code:
          type: string
          nullable: true
        upstream_error_message:
          type: string
          nullable: true
        upstream_error_description:
          type: string
          nullable: true
        upstream_error_param:
          type: string
          nullable: true
        upstream_payload_preview:
          type: string
          nullable: true
        retryable:
          type: boolean
          nullable: true
      additionalProperties: true
    ErrorProviderFailureDiagnostics:
      type: object
      properties:
        category:
          type: string
          enum:
            - credentials_not_configured
            - credentials_invalid_or_forbidden
            - provider_access_missing
            - region_or_project_restriction
            - model_unavailable_for_endpoint
            - rate_limited
            - server_error
        hint:
          type: string
        provider:
          type: string
          nullable: true
    ErrorRoutingDiagnostics:
      type: object
      properties:
        filterStages:
          type: array
          items:
            type: object
            properties:
              stage:
                type: string
              beforeCount:
                type: integer
              afterCount:
                type: integer
              droppedProviders:
                type: array
                items:
                  type: object
                  properties:
                    providerId:
                      type: string
                      nullable: true
                    reason:
                      type: string
                      nullable: true
                  additionalProperties: true
            additionalProperties: true
      additionalProperties: true
    ErrorProviderCandidateDiagnostics:
      type: object
      properties:
        totalProviders:
          type: integer
        supportsEndpointCount:
          type: integer
        candidateCount:
          type: integer
        droppedUnsupportedEndpoint:
          type: array
          items:
            type: string
        droppedMissingAdapter:
          type: array
          items:
            type: object
            properties:
              providerId:
                type: string
                nullable: true
              endpoint:
                type: string
                nullable: true
            additionalProperties: true
      additionalProperties: true
    ErrorProviderEnablementDiagnostics:
      type: object
      properties:
        capability:
          type: string
        providersBefore:
          type: array
          items:
            type: string
        providersAfter:
          type: array
          items:
            type: string
        dropped:
          type: array
          items:
            type: object
            properties:
              providerId:
                type: string
                nullable: true
              reason:
                type: string
                nullable: true
            additionalProperties: true
      additionalProperties: true
    SpendRuleMetric:
      type: string
      description: >-
        spend: بلغ الإنفاق threshold_amount. budget_percent: بلغ الإنفاق
        threshold_percents من الأساس. forecast: يبلغ الإنفاق المتوقع حتى نهاية
        الفترة العتبة. spike: الإنفاق خلال آخر window_hours يساوي
        spike_multiplier مرة على الأقل من وسيط النافذة نفسها خلال الأيام السبعة
        السابقة، ولا يقل عن spike_floor. balance: ينخفض رصيد مساحة العمل أو مدة
        كفايته عن العتبة.
      enum:
        - spend
        - budget_percent
        - forecast
        - spike
        - balance
    SpendRulePeriod:
      type: string
      description: >-
        day أو week (بدءًا من الاثنين) أو month في المنطقة الزمنية للقاعدة، أو
        rolling على آخر window_hours.
      enum:
        - day
        - week
        - month
        - rolling
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: المصادقة باستخدام رمز Bearer

````

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