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

# التنفيذ عبر API

> شغّل نموذجاً منشوراً باستخدام curl أو Python أو JavaScript.

# التنفيذ عبر API

نقطة تشغيل النماذج العامة هي:

```text theme={null}
POST /api/runs
```

كل تشغيل يجب أن يحتوي نموذجاً وinput object ومعاملات اختيارية.

تكاملات المطورين تصادق الطلبات عبر `X-API-Key`. لا تمرر API key داخل
`Authorization: Bearer`؛ bearer tokens خاصة بجلسات المنتج المسجلة الدخول.

## curl

```bash theme={null}
curl -X POST "$AIMP_GATEWAY_URL/api/runs" \
  -H "X-API-Key: $AIMP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "demo-model",
    "mode": "execute",
    "scope": "playground",
    "input": {
      "text": "Write a one-line summary."
    },
    "params": {}
  }'
```

## Python

```python theme={null}
import os
import requests

gateway_url = os.environ["AIMP_GATEWAY_URL"].rstrip("/")
api_key = os.environ["AIMP_API_KEY"]

response = requests.post(
    f"{gateway_url}/api/runs",
    headers={
        "X-API-Key": api_key,
        "Content-Type": "application/json",
    },
    json={
        "model": "demo-model",
        "mode": "execute",
        "scope": "playground",
        "input": {"text": "Write a one-line summary."},
        "params": {},
    },
    timeout=60,
)
response.raise_for_status()
print(response.json())
```

## JavaScript

```javascript theme={null}
const gatewayUrl = process.env.AIMP_GATEWAY_URL.replace(/\/$/, "");

const response = await fetch(`${gatewayUrl}/api/runs`, {
  method: "POST",
  headers: {
    "X-API-Key": process.env.AIMP_API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "demo-model",
    mode: "execute",
    scope: "playground",
    input: { text: "Write a one-line summary." },
    params: {},
  }),
});

if (!response.ok) {
  throw new Error(`AIMP request failed: ${response.status}`);
}

console.log(await response.json());
```

## قائمة تحقق

* `model` هو slug أو معرف نموذج منشور.
* `mode` موجود في عقد النموذج.
* `input` يطابق schema مدخلات النموذج.
* `params` object حتى لو كان فارغاً.
* `scope` موجود للعمليات المعتمدة على vector.
* `index` و`search` يستعملان نفس `scope` عندما يجب أن يقرآ ويكتبا نفس dataset.

## فهرسة وبحث نموذج vector

مدخلات الملفات يجب رفعها قبل التنفيذ. ابدأ الرفع:

```bash theme={null}
curl -X POST "$AIMP_GATEWAY_URL/api/media/upload/init" \
  -H "X-API-Key: $AIMP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "filename": "image.png",
    "content_type": "image/png",
    "media_type": "image",
    "size_bytes": 12345
  }'
```

ارفع bytes الملف إلى `upload_url` الراجع، ثم أكمل الرفع:

```bash theme={null}
curl -X POST "$AIMP_GATEWAY_URL/api/media/upload/complete" \
  -H "X-API-Key: $AIMP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "upload_id": "studio_upload_..."
  }'
```

استعمل `media_ref` الراجع للفهرسة داخل namespace:

```bash theme={null}
curl -X POST "$AIMP_GATEWAY_URL/api/runs" \
  -H "X-API-Key: $AIMP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "clipo",
    "mode": "index",
    "scope": "test",
    "input": {
      "images": [
        {
          "media_ref": "media_...",
          "filename": "image.png"
        }
      ],
      "image_ids": ["image-1"]
    },
    "params": {}
  }'
```

ابحث في نفس البيانات باستعمال نفس `scope`:

```bash theme={null}
curl -X POST "$AIMP_GATEWAY_URL/api/runs" \
  -H "X-API-Key: $AIMP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "clipo",
    "mode": "search",
    "scope": "test",
    "input": {
      "image": {
        "media_ref": "media_...",
        "filename": "query.png"
      }
    },
    "params": {}
  }'
```

البيانات المفهرسة تظهر في Knowledge Bases حسب النموذج والكولكشن والـ scope.
