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

# استخراج القيم

> استخرج قيمًا ذات أنواع محددة من النصوص والصور.

> [!WARNING]
>
> الاستخراج في مرحلة المعاينة. يعتمد توفر النماذج على مسارات المزوّدين المكوّنة.

سمِّ الحقول `fields` التي تريدها وأرسلها مع النص المصدر إلى `POST /v1/extractions` لتحصل على قيم ذات أنواع محددة، مثل رقم فاتورة أو تاريخ أو إجمالي. للاختيار من بين خيارات معروفة بدلًا من ذلك، استخدم [Decisions](https://phaseo.app/docs/ar/v1/api-reference/endpoint/decisions.md).

```bash cURL theme={null}
curl https://api.phaseo.app/v1/extractions \
  -H "Authorization: Bearer $PHASEO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "cloudflare/clairic",
    "input": "Invoice INV-2291: 4 pallets at $250 each, shipping $80.",
    "fields": {
      "invoice_number": { "type": "text" },
      "total": { "type": "number", "decimals": 2, "instructions": "Total including shipping" }
    }
  }'
```

```typescript TypeScript SDK theme={null}
import { Phaseo } from "@phaseo/sdk";

const client = new Phaseo({ apiKey: process.env.PHASEO_API_KEY });
const result = await client.extractions.create({
  model: "cloudflare/clairic",
  input: "Invoice INV-2291: 4 pallets at $250 each, shipping $80.",
  fields: {
    invoice_number: { type: "text" },
    total: { type: "number", decimals: 2, instructions: "Total including shipping" },
  },
});
console.log(result.answers.total.value);
```

```python Python SDK theme={null}
import os
from phaseo import Phaseo

client = Phaseo(api_key=os.environ["PHASEO_API_KEY"])
result = client.extractions.create({
    "model": "cloudflare/clairic",
    "input": "Invoice INV-2291: 4 pallets at $250 each, shipping $80.",
    "fields": {"total": {"type": "number", "decimals": 2,
                         "instructions": "Total including shipping"}},
})
print(result["answers"]["total"]["value"])
```

تحتاج الأمثلة إلى مسار نشط لنموذج استخراج، لذا تحقق من توفر النموذج
قبل إرسال الطلبات. تتيح `AsyncPhaseo` في Python أيضًا
`await client.extractions.create(...)`.

## أنواع الحقول

الأنواع المدعومة هي `text` و`number` و`date` و`time` و`datetime` و`duration` و
`list`. تتطلب القوائم `items: "text"` أو `"number"` أو `"date"`. قدّم من 1 إلى 64 حقلًا
و16,384 حرفًا مصدريًا على الأكثر. تبدأ أسماء الحقول بحرف أو شرطة سفلية،
وتحتوي حتى 64 حرفًا من الأحرف أو الأرقام أو الشرطات السفلية أو النقاط أو الشرطات.

تدعم الأرقام والمدد `integer` و`decimals` (0–6). تقبل المدد
`seconds` و`minutes` و`hours` و`days` و`weeks` و`months` و`years`. اضبط
`reference_date` عندما يعتمد تفسير التواريخ غير المكتملة على سنة محددة.

تستخدم مدخلات الصور كائنات `{ content_type, base64 }`: أربع صور PNG/JPEG/WebP على الأكثر،
4 MiB لكل منها و8 MiB مجتمعة بعد فك الترميز. تُرسل ملفات PDF في `documents` ككائنات
`{ content_type: "application/pdf", base64 }` بحد 4 MiB لكل ملف. لا يمكن أن يتجاوز مجموع الصور وصفحات PDF المعروضة أربعاً،
وتتشارك الصور وملفات PDF حد 8 MiB. تُرفض ملفات PDF المشفّرة. حد الطلب 16 MiB.
العناوين البعيدة والصوت والفيديو والتقديرات والتنبؤات والبث غير مدعومة.

## اقرأ الإجابات

اقرأ `answers[field_name].value`. قد تكون القيمة المفردة `null` عندما لا يحددها
المصدر. `p_null` هو احتمال النموذج لقيمة غير محددة؛
و`confidence` درجة منفصلة يبلغ عنها النموذج. توفّر القوائم الثقة بدون
`p_null`. لا تضمن هذه الدرجات الصحة: اختر عتبات المراجعة المناسبة
لعبء العمل لديك. القائمة الفارغة الصالحة تختلف عن الطلب الفاشل.

تعني `truncated: true` أن المزوّد لم يعالج كل الإدخال المصدري. راجع الإدخال أو
أعد إرساله بطول أقصر قبل الاعتماد على اكتماله. لا تُتاح إزاحات النص ولا التخمينات الخام.
ينبغي إجراء العمليات الحسابية المعقدة في شيفرة التطبيق.

تجمع تقارير الاستخدام `input_tokens` عبر تمريرات المزوّد. يُبلَّغ عن tokens الإخراج
لكنها لا تُحتسب في الفاتورة. استخدم التسعير الذي يُرجعه الـ Gateway بدلًا من تقدير التكلفة من طول المصدر
أو ضرب الاستخدام في عدد الحقول.


## OpenAPI

````yaml ar/openapi/v1/openapi.localized.yaml POST /extractions
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:
  /extractions:
    post:
      tags:
        - Gateway
      summary: استخراج قيم محددة النوع
      description: >-
        يستخرج النصوص والأرقام والتواريخ والأوقات والمدد والقوائم محددة النوع من
        نص أو صور مضمّنة. يعيد قيماً محددة النوع ومعلومات عدم اليقين التي يبلغ
        عنها النموذج. لا يدعم التقديرات أو التنبؤات أو البث أو روابط الصور
        البعيدة.
      operationId: createExtraction
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ExtractionRequest'
      responses:
        '200':
          description: إجابات استخراج محددة النوع
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExtractionResponse'
components:
  schemas:
    ExtractionRequest:
      type: object
      additionalProperties: false
      required:
        - model
        - input
        - fields
      properties:
        model:
          type: string
          minLength: 1
          maxLength: 256
          description: معرّف نموذج يدعم القدرة extraction.extract.
        input:
          type: string
          maxLength: 16384
          description: النص المصدر. يمكن أن يكون فارغاً عند توفير صور أو مستندات.
        fields:
          type: object
          minProperties: 1
          maxProperties: 64
          description: تطابق أسماء الحقول النمط ^[A-Za-z_][A-Za-z0-9_.-]{0,63}$.
          additionalProperties:
            $ref: '#/components/schemas/ExtractionField'
        images:
          type: array
          maxItems: 4
          description: >-
            صور PNG أو JPEG أو WebP مضمّنة؛ 4 MiB لكل صورة و8 MiB إجمالاً بعد فك
            الترميز.
          items:
            $ref: '#/components/schemas/ExtractionImage'
        documents:
          type: array
          maxItems: 4
          description: >-
            مستندات PDF مضمّنة؛ 4 MiB لكل مستند. لا يمكن أن يتجاوز مجموع الصور
            وصفحات PDF المعروضة 4، وتتشارك الصور والمستندات حد 8 MiB بعد فك
            الترميز.
          items:
            $ref: '#/components/schemas/ExtractionDocument'
        reference_date:
          type: string
          format: date
          description: سياق تاريخ صريح للتواريخ غير المكتملة.
    ExtractionResponse:
      type: object
      required:
        - model
        - answers
        - truncated
        - usage
      properties:
        model:
          type: string
        answers:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/ExtractionAnswer'
        truncated:
          type: boolean
          description: يوضح ما إذا كان المزوّد قد اقتطع النص المصدر.
        usage:
          $ref: '#/components/schemas/ExtractionUsage'
    ExtractionField:
      oneOf:
        - $ref: '#/components/schemas/ExtractionTextField'
        - $ref: '#/components/schemas/ExtractionNumberField'
        - $ref: '#/components/schemas/ExtractionDateField'
        - $ref: '#/components/schemas/ExtractionTimeField'
        - $ref: '#/components/schemas/ExtractionDatetimeField'
        - $ref: '#/components/schemas/ExtractionDurationField'
        - $ref: '#/components/schemas/ExtractionListField'
    ExtractionImage:
      type: object
      additionalProperties: false
      required:
        - content_type
        - base64
      properties:
        content_type:
          type: string
          enum:
            - image/png
            - image/jpeg
            - image/webp
        base64:
          type: string
          maxLength: 5592408
          description: بايتات صورة بترميز Base64، دون بادئة رابط بيانات.
    ExtractionDocument:
      type: object
      additionalProperties: false
      required:
        - content_type
        - base64
      properties:
        content_type:
          type: string
          enum:
            - application/pdf
        base64:
          type: string
          maxLength: 5592408
          description: بايتات PDF بترميز Base64، دون بادئة رابط بيانات.
    ExtractionAnswer:
      oneOf:
        - $ref: '#/components/schemas/ExtractionStringAnswer'
        - $ref: '#/components/schemas/ExtractionNumberAnswer'
        - $ref: '#/components/schemas/ExtractionListAnswer'
    ExtractionUsage:
      type: object
      required:
        - input_tokens
        - output_tokens
        - total_tokens
      properties:
        input_tokens:
          type: integer
          minimum: 0
          description: إجمالي رموز الإدخال عبر جميع التمريرات، كما أبلغ عنه المزوّد.
        output_tokens:
          type: integer
          minimum: 0
          description: >-
            رموز الإخراج لقيم الحقول المفكوكة، كما أبلغ عنها المزوّد. لا تُحتسب
            رموز الإخراج في الفاتورة.
        total_tokens:
          type: integer
          minimum: 0
    ExtractionTextField:
      type: object
      additionalProperties: false
      required:
        - type
      properties:
        type:
          type: string
          enum:
            - text
        instructions:
          type: string
          maxLength: 2048
    ExtractionNumberField:
      type: object
      additionalProperties: false
      required:
        - type
      properties:
        type:
          type: string
          enum:
            - number
        instructions:
          type: string
          maxLength: 2048
        integer:
          type: boolean
        decimals:
          type: integer
          minimum: 0
          maximum: 6
        unit:
          type: string
          maxLength: 64
    ExtractionDateField:
      type: object
      additionalProperties: false
      required:
        - type
      properties:
        type:
          type: string
          enum:
            - date
        instructions:
          type: string
          maxLength: 2048
    ExtractionTimeField:
      type: object
      additionalProperties: false
      required:
        - type
      properties:
        type:
          type: string
          enum:
            - time
        instructions:
          type: string
          maxLength: 2048
    ExtractionDatetimeField:
      type: object
      additionalProperties: false
      required:
        - type
      properties:
        type:
          type: string
          enum:
            - datetime
        instructions:
          type: string
          maxLength: 2048
    ExtractionDurationField:
      type: object
      additionalProperties: false
      required:
        - type
      properties:
        type:
          type: string
          enum:
            - duration
        instructions:
          type: string
          maxLength: 2048
        integer:
          type: boolean
        decimals:
          type: integer
          minimum: 0
          maximum: 6
        unit:
          type: string
          enum:
            - seconds
            - minutes
            - hours
            - days
            - weeks
            - months
            - years
    ExtractionListField:
      type: object
      additionalProperties: false
      required:
        - type
        - items
      properties:
        type:
          type: string
          enum:
            - list
        instructions:
          type: string
          maxLength: 2048
        items:
          type: string
          enum:
            - text
            - number
            - date
        decimals:
          type: integer
          minimum: 0
          maximum: 6
    ExtractionStringAnswer:
      type: object
      required:
        - type
        - value
        - confidence
        - p_null
      properties:
        type:
          type: string
          enum:
            - text
            - date
            - time
            - datetime
        value:
          type: string
          description: نص مستخرج أو تاريخ/وقت بصيغة ISO، أو null عند تعذر تحديده.
          nullable: true
        confidence:
          type: number
          minimum: 0
          maximum: 1
          description: ثقة يبلغ عنها النموذج؛ لا تضمن صحة النتيجة.
        p_null:
          type: number
          minimum: 0
          maximum: 1
          description: احتمال تعذر تحديد القيمة.
    ExtractionNumberAnswer:
      type: object
      required:
        - type
        - value
        - confidence
        - p_null
      properties:
        type:
          type: string
          enum:
            - number
            - duration
        value:
          type: number
          nullable: true
        confidence:
          type: number
          minimum: 0
          maximum: 1
        p_null:
          type: number
          minimum: 0
          maximum: 1
    ExtractionListAnswer:
      type: object
      required:
        - type
        - value
        - confidence
      properties:
        type:
          type: string
          enum:
            - list
        value:
          type: array
          maxItems: 4096
          items:
            oneOf:
              - type: string
              - type: number
        confidence:
          type: number
          minimum: 0
          maximum: 1
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: المصادقة باستخدام رمز Bearer

````

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