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

# إنشاء جلسة

> إنشاء جلسة مصادقة محددة بوقت لوكيل آلة مع رموز وصول محددة النطاق

# إنشاء جلسة

`POST /v1/agent-sessions`

ينشئ جلسة مصادقة جديدة لوكيل آلة. تربط الجلسة رمز وصول محدود الوقت ورمز تحديث بالوكيل، مع مجموعة نطاق صريحة يجب أن تكون مجموعة فرعية من النطاقات الممنوحة للوكيل.

يتم إرجاع `token` و`refresh_token` فقط في استجابة الإنشاء. قم بتخزينها بأمان - لا يمكن استردادها لاحقًا.

> [!WARNING]
>
> يتم إرجاع حقلي `token` و `refresh_token` مرة واحدة فقط في هذا
> الاستجابة. قم بتخزينها في مدير أسرار آمن أو تخزين مشفر
> فورًا. إذا فقدت، قم بإنهاء الجلسة وإنشاء جلسة جديدة.

### المصادقة

يتطلب رأس `X-API-Key` أو رمز Bearer JWT. يتم اشتقاق مساحة العمل من بيانات الاعتماد الموثقة؛ لا ترسل `X-Tenant-ID`.

### الاستجابة

**session** `object`

كائن الجلسة الذي تم إنشاؤه ويحتوي على:

**session.id** `string`

المفتاح الأساسي UUID الداخلي.

**session.session\_id** `string`

معرف جلسة MAIP بالتنسيق `maip-sess:<short-uuid>:<random-hex>`.
استخدم هذا المعرف في استدعاءات API اللاحقة.

**session.agent\_id** `string`

الوكيل الذي تنتمي إليه هذه الجلسة.

**session.status** `string`

حالة الجلسة. دائمًا `"active"` عند الإنشاء.

**session.scopes** `string[]`

النطاقات الفعالة لهذه الجلسة.

**session.metadata** `object`

بيانات تعريف الجلسة.

**session.expires\_at** `string`

طابع زمني لانتهاء صلاحية ISO 8601.

**session.created\_at** `string`

طابع زمني لإنشاء ISO 8601.

**session.updated\_at** `string`

طابع زمني لآخر تحديث ISO 8601.

**token** `string`

رمز وصول مبهم لمصادقة طلبات API داخل هذه الجلسة.
سلسلة سداسية عشرية مكونة من 64 حرفًا. **تُرجع مرة واحدة فقط.**

**refresh\_token** `string`

رمز لتحديث الجلسة قبل انتهاء صلاحيتها. سلسلة سداسية عشرية مكونة من 64 حرفًا.
**يتم إرجاعه مرة واحدة فقط.**

### مثال

```bash theme={null}
curl -X POST https://api.truthlocks.com/v1/agent-sessions \
  -H "X-API-Key: tl_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "agent_id": "maip:t1234567:01HYX3KPZQ7RJGBN0WFMV8SDEH",
    "scopes": ["data:read", "tool:search.web"],
    "ttl_minutes": 120,
    "metadata": {
      "purpose": "customer-inquiry-batch-2026-04-06",
      "orchestrator": "support-pipeline-v2"
    }
  }'
```

***

### دورة حياة الجلسة

```
Created (active) --> Refreshed (active) --> Expired (expired)
      |                                         |
      +--> Terminated (terminated)               |
      |                                         |
      +--> Handed Off (handed_off) --> New Session (active)
```

يتم إنشاء إيصال الجلسة تلقائيًا عند بدء الجلسة، مما يربط الجلسة بمسار تدقيق الوكيل.


## OpenAPI

````yaml ar/mint-openapi.yaml POST /v1/agent-sessions
openapi: 3.0.3
info:
  title: Truthlocks API
  description: >
    Truthlocks هي بنية تحتية عالمية للتحقق من المستندات وبيانات الاعتماد والأصول
    الرقمية.يحدد هذا المواصفات واجهة برمجة التطبيقات (API) الأساسية للتفاعل مع
    خدمات Truthlocks.


    ## عناوين URL الأساسية

    - **الإنتاج**: `https://api.truthlocks.com`

    - **البيئة التجريبية (Sandbox)**: `https://sandbox-api.truthlocks.com`


    ## المصادقة

    - **مفاتيح API**: استخدم رأس `X-API-Key` للعمليات من جهاز إلى جهاز

    - **رموز Bearer**: استخدم `Authorization: Bearer <jwt>` للعمليات التي يبدأها
    المستخدم


    ## هوية المستأجر

    في بيئة الإنتاج، تُستمد هوية المستأجر من السياق المصادق عليه (مفتاح API أو
    JWT).

    يتم تجاهل رأس `X-Tenant-ID` في بيئة الإنتاج لمنع الانتحال.
  version: 1.0.0
  contact:
    name: Truthlocks Support
    url: https://truthlocks.com/support
    email: support@truthlocks.com
servers:
  - url: https://api.truthlocks.com
    description: واجهة برمجة تطبيقات الإنتاج
  - url: https://sandbox-api.truthlocks.com
    description: بيئة اختبار (Sandbox)
security:
  - APIKey: []
  - BearerAuth: []
tags:
  - name: Authentication
    description: إدارة مفاتيح ورموز API
  - name: Issuers
    description: تسجيل المصدر وإدارة الثقة
  - name: Keys
    description: إدارة المفاتيح التشفيرية لجهات الإصدار
  - name: Attestations
    description: دورة حياة الإشهاد (السك، الإلغاء، الاستبدال)
  - name: Verification
    description: حزم التحقق والإثبات للإشهاد
  - name: Governance
    description: سير عمل حوكمة المصدر (للمسؤول فقط)
  - name: Identity
    description: إدارة المنظمة والمستخدمين والأدوار
  - name: Audit
    description: استعلامات أحداث التدقيق
  - name: Tenant Console
    description: ملف تعريف المستأجر ونقاط نهاية دورة الحياة
  - name: Health
    description: نقاط نهاية صحة الخدمة وجاهزيتها
  - name: Risk
    description: استيعاب إشارة المخاطر واكتشاف الاحتيال
  - name: Risk Enforcement
    description: إجراءات إنفاذ المخاطر — الحظر والتحدي والحجر والتكوين
  - name: Billing
    description: إدارة الفوترة والاشتراكات والإضافات
  - name: Machine Identity
    description: >-
      بروتوكول هوية وكيل الآلة (MAIP) — تسجيل الوكيل، الجلسات، الثقة، الشهادة،
      الامتثال، التنسيق، والمراقبة
externalDocs:
  description: واجهة برمجة تطبيقات الشفافية للقراءة فقط (مواصفات خدمة منفصلة)
  url: >-
    https://github.com/truthlocks/truthlock/blob/main/docs/transparency/openapi.yaml
paths:
  /v1/agent-sessions:
    post:
      tags:
        - Machine Identity
      summary: إنشاء جلسة
      description: >-
        ينشئ جلسة قصيرة الأجل لوكيل. يتم إرجاع رمز الجلسة مرة واحدة ويجب
        استخدامه في الطلبات اللاحقة ضمن نافذة TTL.
      operationId: maip.sessions.create
      requestBody:
        required: true
        content:
          application/json:
            schema:
              properties:
                agent_id:
                  type: string
                  description: الوكيل لإنشاء الجلسة له
                  format: uuid
                metadata: {}
                scopes:
                  items:
                    type: string
                  type: array
                  description: >-
                    نطاقات هذه الجلسة (يجب أن تكون مجموعة فرعية من نطاقات
                    الوكيل)
                ttl_minutes:
                  type: integer
              type: object
              required:
                - agent_id
      responses:
        '201':
          description: تم إنشاء الجلسة
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MaipSession'
        '400':
          description: خطأ في التحقق
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '401':
          description: المصادقة مطلوبة
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '404':
          description: لم يتم العثور على الوكيل
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '429':
          description: تجاوز حد المعدل
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
      security:
        - APIKey: []
components:
  schemas:
    MaipSession:
      type: object
      properties:
        session_id:
          type: string
          format: uuid
        agent_id:
          type: string
          format: uuid
        token:
          type: string
          description: رمز حامل الجلسة (يُرجع مرة واحدة عند الإنشاء)
        scopes:
          type: array
          items:
            type: string
        status:
          type: string
          enum:
            - active
            - terminated
            - expired
        metadata:
          type: object
          additionalProperties: true
        expires_at:
          type: string
          format: date-time
        created_at:
          type: string
          format: date-time
        terminated_at:
          type: string
          format: date-time
    ErrorEnvelope:
      type: object
      required:
        - code
        - message
        - http_status
      properties:
        code:
          type: string
          description: رمز خطأ قابل للقراءة آليًا
          enum:
            - AUTH_REQUIRED
            - AUTH_INVALID
            - PERMISSION_DENIED
            - TENANT_IDENTITY_UNVERIFIED
            - NOT_FOUND
            - VALIDATION_ERROR
            - CONFLICT
            - PAYLOAD_TOO_LARGE
            - RATE_LIMIT_EXCEEDED
            - QUOTA_EXCEEDED
            - SERVICE_UNAVAILABLE
            - INTERNAL_ERROR
        message:
          type: string
          description: رسالة خطأ مقروءة بشريًا
        http_status:
          type: integer
          description: رمز حالة HTTP
        retry_after_ms:
          type: integer
          description: عدد المللي ثانية للانتظار قبل إعادة المحاولة (لحدود المعدل)
        details:
          type: object
          description: سياق خطأ إضافي
      example:
        code: AUTH_REQUIRED
        message: Authentication required
        http_status: 401
  securitySchemes:
    APIKey:
      type: apiKey
      in: header
      name: X-API-Key
      description: مفتاح API للمصادقة من جهاز إلى جهاز
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: JWT للعمليات التي يبدأها المستخدم

````

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