# Messages (Anthropic)

> POST /v1/messages בפורמט Messages של Anthropic, שבו משתמשים ה-SDK של Anthropic ו-Claude Code.


הבקשה והתשובה של Anthropic Messages, על מודלים של NotHoly. ה-SDK של Anthropic מקבל את `https://api.notholy.com` ככתובת בסיס, בלי `/v1`. אפשר לשלוח את המפתח בכותרת `x-api-key` או בכותרת `Authorization: Bearer`.

```endpoint
POST https://api.notholy.com/v1/messages
```

## בקשה

| שדה | סוג | חובה | הערות |
|---|---|---|---|
| `model` | string | כן | מזהה מודל, למשל `notholy-specter` |
| `max_tokens` | number | כן | גדול מ-0. מוגבל לפלט המקסימלי של המודל |
| `messages` | array | כן | תורות של `user` ושל `assistant` עם בלוקים מסוג `text`, `image`, `tool_use` או `tool_result`. אפשר לשלוח גם תורות `system` בין ההודעות |
| `system` | string או array | לא | בלוקי טקסט בלבד |
| `tools` | array | לא | הכלים שלך עם `input_schema`. כלי שרת, כמו חיפוש ברשת, מושמטים |
| `tool_choice` | object | לא | `auto`, `any`, `none` או `{"type": "tool", "name": …}` |
| `thinking` | object | לא | `{"type": "enabled", "budget_tokens": N}` או `{"type": "adaptive"}` מפעילים חשיבה |
| `output_config.effort` | string | לא | מאמץ חשיבה. גובר על השדה `thinking`, וממופה לרמה הקרובה ביותר שיש למודל |
| `stop_sequences`, `temperature`, `top_p` | | לא | מועברים למודל |
| `stream` | boolean | לא | הערך `true` מחזיר אירועי stream של Anthropic |

הקריאה `POST /v1/messages/count_tokens` מקבלת את אותו גוף ומחזירה `{"input_tokens": n}`. זו הערכה שמחושבת בלי לקרוא למודל.

## תשובה בלי סטרימינג

```json
{
  "id": "msg_3Jd8a",
  "type": "message",
  "role": "assistant",
  "model": "notholy-specter",
  "content": [
    { "type": "thinking", "thinking": "…", "signature": "nh" },
    { "type": "text", "text": "A Sigma rule is a generic detection rule in YAML…" }
  ],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": { "input_tokens": 24, "output_tokens": 131, "cache_read_input_tokens": 0, "cache_creation_input_tokens": 0 }
}
```

- הערך של `stop_reason` הוא `end_turn`, `max_tokens` או `tool_use`.
- בלוקי `thinking` שנשלחים בחזרה בהיסטוריה מוסרים לפני שהמודל רואה אותם.
- השדה `cache_control` מתקבל אבל לא משפיע.
- מקורות `document` מסוג PDF או קובץ מחזירים `400 unsupported_parameter`. קבצים שולחים דרך הצ׳אט או דרך `POST /v1/files`.
- בסטרימינג, קריאות לכלים מגיעות בשלמותן: `input_json_delta` אחד עם כל הארגומנטים. בהפסקות ארוכות נשלחים אירועי `ping`.

## דוגמה

```bash test
curl https://api.notholy.com/v1/messages \
  -H "x-api-key: $NOTHOLY_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{"model": "notholy-specter", "max_tokens": 512, "messages": [{"role": "user", "content": "What is a Sigma rule?"}]}'
```

```python test
import os
from anthropic import Anthropic

client = Anthropic(base_url="https://api.notholy.com", api_key=os.environ["NOTHOLY_API_KEY"])

with client.messages.stream(
    model="notholy-specter",
    max_tokens=512,
    messages=[{"role": "user", "content": "Write a Sigma rule title for encoded PowerShell."}],
) as s:
    for text in s.text_stream:
        print(text, end="")
print()
```

ספירת טוקנים לפני השליחה:

```bash test
curl https://api.notholy.com/v1/messages/count_tokens \
  -H "x-api-key: $NOTHOLY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "notholy-specter", "messages": [{"role": "user", "content": "What is a Sigma rule?"}]}'
```

## שגיאות

השגיאות בפורמט של Anthropic, `{"type": "error", "error": {"type", "message"}}`: `invalid_request_error` (400) · `authentication_error` (401) · `billing_error` (402) · `permission_error` (403) · `not_found_error` (404) · `rate_limit_error` (429) · `request_too_large` (413) · `api_error` (500, 502, 504) · `overloaded_error` (503). פרטים ב[שגיאות](/he/guides/errors).
