تخطَّ إلى المحتوى
مرجع API
مرجع API

رسائل Anthropic

أرسل طلباً عبر عملية Messages المتوافقة مع Anthropic في RunAPI.

01

نظرة عامة

استخدم عملية Messages المتوافقة مع Anthropic في RunAPI مع نموذج متوافق وأشكال الطلب والاستجابة الخاصة بالبروتوكول.

البدء السريع

  1. أنشئ مفتاح API واضبطه كـ RUNAPI_API_KEY.
  2. اختر نموذجاً متوافقاً، ثم أرسل معاملات المسار الموثَّقة وجسم JSON.
  3. اقرأ استجابة JSON أو أحداث الخادم المُرسَلة المعروضة لهذه العملية، وتعامل مع أخطاء البروتوكول.

نقطة النهاية

POST /v1/messages
عنوان URL الأساسي
https://runapi.ai
إصدار العقد
v1
المصادقة المفضّلة
x-api-key: YOUR_API_TOKEN
02

وسائل حمل المصادقة

يقبل RunAPI كل بروتوكول مُدرج أدناه. تستخدم العينات المُولَّدة الترويسة المفضَّلة للبروتوكول.

header
Authorization: Bearer YOUR_API_TOKEN
header - مفضّل
x-api-key: YOUR_API_TOKEN
header
x-goog-api-key: YOUR_API_TOKEN
query
?key=YOUR_API_TOKEN
03

النماذج المتوافقة

افتح صفحة النموذج للاطلاع على التسعير الحالي وحدود المعدل وتفاصيل الاستخدام التجاري.

عرض 58 نموذجاً متوافقاً
04

عقد الطلب

نص JSON

تُدرج فقط الحقول التي تتوفر لها أدلة دعم من بروتوكول عام ومن RunAPI. تُمرَّر حقول نص JSON الإضافية كما هي.

جسم JSON10 حقل
max_tokensinteger
مطلوب

الحد الأقصى لعدد الرموز المراد توليدها قبل التوقف.

messagesarray
مطلوب

أدوار المحادثة بتنسيق Anthropic Messages.

messages[].content["string", "array"]
مطلوب
messages[].rolestring
مطلوب
modelstring
مطلوب

معرّف نموذج RunAPI الذي يُرجعه كتالوج النماذج المتوافق.

streamboolean
اختياري

إرجاع أحداث Messages المكتوبة كأحداث مُرسَلة من الخادم.

القيمة الافتراضية: false
system["string", "array"]
اختياري

تعليمات النظام المُقدَّمة بمعزل عن رسائل المحادثة.

temperaturenumber
اختياري

درجة حرارة أخذ العينات؛ قد يتفاوت دعم النموذج.

toolsarray
اختياري

الأدوات التي يمكن للنموذج استدعاؤها.

top_pnumber
اختياري

احتمال أخذ العيّنة النواتية؛ قد يتفاوت دعم النموذج لها.

مثال على الطلب

JSON
{
  "max_tokens": 64,
  "messages": [
    {
      "content": "Summarize one practical improvement for an API deployment.",
      "role": "user"
    }
  ],
  "model": "claude-sonnet-4-6"
}
05

استجابة متزامنة

HTTP 200

المخطط

JSON
{
  "additionalProperties": true,
  "properties": {
    "content": {
      "type": "array"
    },
    "id": {
      "type": "string"
    },
    "model": {
      "type": "string"
    },
    "role": {
      "const": "assistant",
      "type": "string"
    },
    "stop_reason": {
      "type": [
        "string",
        "null"
      ]
    },
    "type": {
      "const": "message",
      "type": "string"
    },
    "usage": {
      "additionalProperties": true,
      "properties": {
        "input_tokens": {
          "type": "integer"
        },
        "output_tokens": {
          "type": "integer"
        }
      },
      "required": [
        "input_tokens",
        "output_tokens"
      ],
      "type": "object"
    }
  },
  "required": [
    "id",
    "type",
    "role",
    "content",
    "model",
    "stop_reason",
    "usage"
  ],
  "type": "object"
}

مثال

JSON
{
  "content": [
    {
      "text": "Hello! How can I help today?",
      "type": "text"
    }
  ],
  "id": "msg_example",
  "model": "claude-sonnet-4-6",
  "role": "assistant",
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "type": "message",
  "usage": {
    "input_tokens": 12,
    "output_tokens": 8
  }
}
06

حدث SSE: message_start

text/event-stream

المخطط

JSON
{
  "additionalProperties": true,
  "properties": {
    "message": {
      "type": "object"
    },
    "type": {
      "const": "message_start",
      "type": "string"
    }
  },
  "required": [
    "type",
    "message"
  ],
  "type": "object"
}

مثال

JSON
{
  "message": {
    "content": [],
    "id": "msg_example",
    "model": "claude-sonnet-4-6",
    "role": "assistant",
    "stop_reason": null,
    "stop_sequence": null,
    "type": "message",
    "usage": {
      "input_tokens": 12,
      "output_tokens": 1
    }
  },
  "type": "message_start"
}
07

حدث SSE: content_block_delta

text/event-stream

المخطط

JSON
{
  "additionalProperties": true,
  "properties": {
    "delta": {
      "type": "object"
    },
    "index": {
      "type": "integer"
    },
    "type": {
      "const": "content_block_delta",
      "type": "string"
    }
  },
  "required": [
    "type",
    "index",
    "delta"
  ],
  "type": "object"
}

مثال

JSON
{
  "delta": {
    "text": "Hello",
    "type": "text_delta"
  },
  "index": 0,
  "type": "content_block_delta"
}
08

حدث SSE: message_delta

text/event-stream

المخطط

JSON
{
  "additionalProperties": true,
  "properties": {
    "delta": {
      "type": "object"
    },
    "type": {
      "const": "message_delta",
      "type": "string"
    },
    "usage": {
      "additionalProperties": true,
      "properties": {
        "output_tokens": {
          "type": "integer"
        }
      },
      "required": [
        "output_tokens"
      ],
      "type": "object"
    }
  },
  "required": [
    "type",
    "delta",
    "usage"
  ],
  "type": "object"
}

مثال

JSON
{
  "delta": {
    "stop_reason": "end_turn",
    "stop_sequence": null
  },
  "type": "message_delta",
  "usage": {
    "output_tokens": 8
  }
}
09

حدث SSE: message_stop

text/event-stream

المخطط

JSON
{
  "additionalProperties": true,
  "properties": {
    "type": {
      "const": "message_stop",
      "type": "string"
    }
  },
  "required": [
    "type"
  ],
  "type": "object"
}

مثال

JSON
{
  "type": "message_stop"
}
10

خطأ في البروتوكول: invalid_request

HTTP 400

المخطط

JSON
{
  "additionalProperties": true,
  "properties": {
    "error": {
      "additionalProperties": true,
      "properties": {
        "message": {
          "type": "string"
        },
        "type": {
          "type": "string"
        }
      },
      "required": [
        "type",
        "message"
      ],
      "type": "object"
    },
    "request_id": {
      "type": "string"
    },
    "type": {
      "const": "error",
      "type": "string"
    }
  },
  "required": [
    "type",
    "error"
  ],
  "type": "object"
}

مثال

JSON
{
  "error": {
    "message": "max_tokens is required",
    "type": "invalid_request_error"
  },
  "request_id": "req_example",
  "type": "error"
}
11

الاستخدام

المخطط

JSON
{
  "additionalProperties": true,
  "properties": {
    "input_tokens": {
      "type": "integer"
    },
    "output_tokens": {
      "type": "integer"
    }
  },
  "required": [
    "input_tokens",
    "output_tokens"
  ],
  "type": "object"
}

مثال

JSON
{
  "input_tokens": 12,
  "output_tokens": 8
}
12

نماذج الأكواد المولَّدة

كل نموذج من نماذج cURL وJavaScript وPython يُرسل الطلب المُتحقق منه من هذا العقد دون الحاجة إلى SDK خاص بالبروتوكول.

التثبيت

Shell
pip install requests
PYTHON
import requests

response = requests.post(
    "https://runapi.ai/v1/messages",
    headers={"x-api-key": "YOUR_API_TOKEN", "Content-Type": "application/json"},
    json={"model": "claude-sonnet-4-6", "max_tokens": 64, "messages": [{"role": "user", "content": "Summarize one practical improvement for an API deployment."}]}
)
response.raise_for_status()
print(response.json())