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

# Bots API

> HTTP से अपने Krea बॉट्स से बात करें: बॉट्स की सूची देखें, चैट शुरू करें, मैसेज भेजें, जवाब पोल करें, सवालों के जवाब दें, और किसी टर्न को रोकें या दोबारा चलाएँ।

अपने ऐप्लिकेशन से Krea बॉट्स के साथ काम करने के लिए Bots API इस्तेमाल करें। API कुंजी वही करती है जो उसका व्यक्ति बॉट चैट में करता है: API से भेजा गया मैसेज वही बॉट टर्न शुरू करता है और उसी चैट में दिखता है जिसमें Krea ऐप से भेजा गया मैसेज दिखता है। रिक्वेस्ट और रिस्पॉन्स snake\_case JSON फ़ील्ड इस्तेमाल करते हैं।

| एंडपॉइंट | उद्देश्य |
| - | - |
| [`GET /bots`](https://www.krea.ai/docs/api-reference/bots/list-bots) | वे बॉट्स दिखाता है जिन्हें आप इस्तेमाल कर सकते हैं। |
| [`GET /bots/{bot_id}`](https://www.krea.ai/docs/api-reference/bots/get-bot) | एक बॉट पढ़ता है। |
| [`GET /bots/chats`](https://www.krea.ai/docs/api-reference/bots/list-bot-chats) | वे चैट दिखाता है जिनमें आप हैं, सबसे नई पहले। |
| [`POST /bots/chats`](https://www.krea.ai/docs/api-reference/bots/start-bot-chat) | किसी बॉट के साथ डायरेक्ट चैट, या कई बॉट्स और टीममेट्स के साथ ग्रुप चैट खोलता है। |
| [`GET /bots/chats/{chat_id}`](https://www.krea.ai/docs/api-reference/bots/get-bot-chat) | किसी चैट को उसके मैसेज के एक पेज के साथ पढ़ता है। |
| [`DELETE /bots/chats/{chat_id}`](https://www.krea.ai/docs/api-reference/bots/delete-bot-chat) | चैट को उसमें मौजूद सभी लोगों के लिए डिलीट करता है। |
| [`GET /bots/chats/{chat_id}/messages`](https://www.krea.ai/docs/api-reference/bots/read-new-bot-chat-messages) | नए मैसेज और चैट की स्थिति पोल करता है। |
| [`POST /bots/chats/{chat_id}/messages`](https://www.krea.ai/docs/api-reference/bots/send-bot-chat-message) | चैट में मैसेज भेजता है। |
| [`POST /bots/chats/{chat_id}/members`](https://www.krea.ai/docs/api-reference/bots/add-bot-chat-members) | चैट में बॉट्स और टीममेट्स जोड़ता है। |
| [`DELETE /bots/chats/{chat_id}/members/{member_id}`](https://www.krea.ai/docs/api-reference/bots/remove-bot-chat-member) | ग्रुप चैट से किसी व्यक्ति को हटाता है, या आपको उससे बाहर करता है। |
| [`DELETE /bots/chats/{chat_id}/bots/{bot_id}`](https://www.krea.ai/docs/api-reference/bots/remove-bot-from-chat) | ग्रुप चैट से बॉट को हटाता है। |
| [`POST /bots/chats/{chat_id}/questions/{question_id}/answer`](https://www.krea.ai/docs/api-reference/bots/answer-bot-question) | उस सवाल का जवाब देता है जिसका बॉट इंतज़ार कर रहा है। |
| [`POST /bots/chats/{chat_id}/stop`](https://www.krea.ai/docs/api-reference/bots/stop-bot-chat) | चैट में काम कर रहे बॉट्स को रोकता है। |
| [`POST /bots/chats/{chat_id}/retry`](https://www.krea.ai/docs/api-reference/bots/retry-bot-chat) | उन बॉट्स को फिर से चालू करता है जो वर्कस्पेस की कंप्यूट यूनिट खत्म होने से रुके थे। |

बॉट बैकग्राउंड में काम करते हैं। मैसेज भेजने पर तुरंत एक `cursor` मिलता है। फिर आप उस cursor से चैट पोल करते हैं, जब तक बॉट काम पूरा न कर लें, सवाल न पूछें, फ़ेल न हों या रोके न जाएँ। कोई स्ट्रीमिंग या वेबहुक नहीं है।

## ऑथेंटिकेशन और एक्सेस

`https://api.krea.ai` को भेजी जाने वाली हर रिक्वेस्ट के साथ `Authorization: Bearer KREA_API_KEY` भेजें। Bots API बाकी [पब्लिक API](https://www.krea.ai/docs/hi/developers/api-keys-and-billing.md) वाली ही कुंजियाँ इस्तेमाल करता है।

कुंजी का वर्कस्पेस और व्यक्ति तय करते हैं कि आप क्या देख सकते हैं:

* **बॉट्स:** आपके अपने बॉट्स, और वर्कस्पेस के साथ शेयर किए गए बॉट्स।
* **चैट:** सिर्फ़ वे चैट जिनमें आप हैं। जिस चैट में आप नहीं हैं, वह `404` लौटाती है, एक ही वर्कस्पेस के टीममेट्स के लिए भी।

Bots के लिए Max या उससे ऊपर का प्लान, या Bots का आमंत्रण चाहिए। इसके बिना stop को छोड़कर हर एंडपॉइंट `403` लौटाता है:

```json theme={"theme":{"light":"github-light-default","dark":"vesper"}}
{
  "error": "Bots needs a Max plan or higher. Upgrade at https://www.krea.ai/pricing to work with bots.",
  "code": "entitlement_denied",
  "required_plan": "Max"
}
```

जिस अकाउंट के लिए Bots अभी खुला नहीं है, उसे `code: "bots_unavailable"` के साथ `403` मिलता है। प्लान की वजह से stop कभी मना नहीं होता, इसलिए चल रहा काम हमेशा रोका जा सकता है।

हर चैट रिस्पॉन्स में एक `url` होता है जो Krea ऐप में चैट खोलता है। API से भेजे गए मैसेज वहाँ **via API** के रूप में दिखते हैं, और दोबारा पढ़ने पर उनमें `"via": "API"` होता है।

## बिलिंग

> [!NOTE]
>
> बॉट टर्न वर्कस्पेस का कंप्यूट यूनिट बैलेंस इस्तेमाल करते हैं, ठीक Krea ऐप के टर्न की तरह। ये API बैलेंस इस्तेमाल **नहीं** करते। किसी बॉट या चैट पर तय की गई यूसेज लिमिट भी लागू होती हैं।

वर्कस्पेस की कंप्यूट यूनिट खत्म होने पर भी मैसेज स्वीकार किया जाता है। रोक तब दिखती है जब आप चैट पढ़ते हैं। [कंप्यूट यूनिट खत्म होना और यूसेज लिमिट](#out-of-compute-units-and-usage-limits) देखें।

## मैसेज भेजें और जवाब पोल करें

पहले अपने एनवायरनमेंट में `KREA_API_KEY` सेट करें। `curl` और `jq` के साथ Bash, `requests` के साथ Python, या बिल्ट-इन `fetch` के साथ Node.js चुनें। आपके पास कम से कम एक बॉट होना चाहिए। बॉट Krea ऐप में बनाएँ; API बॉट नहीं बनाता।

**1. अपने बॉट्स की सूची देखें**

`GET /bots` वे बॉट्स लौटाता है जिन्हें आप इस्तेमाल कर सकते हैं। किसी बॉट का `id` चुनें।

**2. चैट शुरू करें**

`bot_id`, एक `title` और एक `message` के साथ `POST /bots/chats` कॉल करें। लौटे हुए `chat_id` और `cursor` सेव करें।

**3. जवाब पोल करें**

`cursor` और `wait=30` के साथ `GET /bots/chats/{chat_id}/messages` कॉल करें। हर रिस्पॉन्स के नए `cursor` के साथ तब तक दोहराएँ जब तक `status` का मान `working` न रहे।

```bash cURL theme={"theme":{"light":"github-light-default","dark":"vesper"}}
set -euo pipefail
: "${KREA_API_KEY:?Set your Krea API key}"
API=https://api.krea.ai
AUTH="Authorization: Bearer $KREA_API_KEY"

BOT_ID=$(curl --fail-with-body --silent --show-error --max-time 60 \
  "$API/bots" -H "$AUTH" | jq -er '.bots[0].id')

START=$(curl --fail-with-body --silent --show-error --max-time 60 \
  "$API/bots/chats" \
  -H "$AUTH" \
  -H "Content-Type: application/json" \
  -d "$(jq -n --arg bot_id "$BOT_ID" '{
    bot_id: $bot_id,
    title: "Coffee mug campaign",
    message: "Create three square product images for a ceramic coffee mug on a neutral studio background. Use no text or logos."
  }')")

CHAT_ID=$(printf '%s' "$START" | jq -er '.chat_id')
CURSOR=$(printf '%s' "$START" | jq -er '.cursor')
printf '%s' "$START" | jq -r '.url'

DEADLINE=$((SECONDS + 300))

while (( SECONDS < DEADLINE )); do
  STATE=$(curl --fail-with-body --silent --show-error --max-time 45 --get \
    "$API/bots/chats/$CHAT_ID/messages" \
    -H "$AUTH" \
    --data-urlencode "cursor=$CURSOR" \
    --data-urlencode "wait=30")
  CURSOR=$(printf '%s' "$STATE" | jq -er '.cursor')
  printf '%s' "$STATE" | jq '{status, text, media, files, question, error}'
  STATUS=$(printf '%s' "$STATE" | jq -er '.status')
  if [[ "$STATUS" != "working" ]]; then
    if [[ "$STATUS" == "done" ]]; then exit 0; fi
    printf 'Chat is %s. Open %s\n' "$STATUS" "$(printf '%s' "$STATE" | jq -r '.url')" >&2
    exit 1
  fi
done

printf 'Wait budget exhausted; the bot keeps working. Resume with chat_id=%s cursor=%s\n' \
  "$CHAT_ID" "$CURSOR" >&2
exit 1
```

```python Python theme={"theme":{"light":"github-light-default","dark":"vesper"}}
import json
import os
import time
import requests

api = "https://api.krea.ai"
headers = {"Authorization": f"Bearer {os.environ['KREA_API_KEY']}"}

response = requests.get(f"{api}/bots", headers=headers, timeout=60)
response.raise_for_status()
bots = response.json()["bots"]
if not bots:
    raise SystemExit("No bots yet. Create one in the Krea app first.")

response = requests.post(
    f"{api}/bots/chats",
    headers=headers,
    json={
        "bot_id": bots[0]["id"],
        "title": "Coffee mug campaign",
        "message": "Create three square product images for a ceramic coffee mug on a neutral studio background. Use no text or logos.",
    },
    timeout=60,
)
response.raise_for_status()
start = response.json()
chat_id, cursor = start["chat_id"], start["cursor"]
print(start["url"])

deadline = time.monotonic() + 300
while True:
    if time.monotonic() > deadline:
        raise TimeoutError(
            "Wait budget exhausted; the bot keeps working. Resume with "
            f"chat_id={chat_id} cursor={cursor}"
        )
    response = requests.get(
        f"{api}/bots/chats/{chat_id}/messages",
        headers=headers,
        params={"cursor": cursor, "wait": 30},
        timeout=45,
    )
    response.raise_for_status()
    state = response.json()
    cursor = state["cursor"]
    print(state["text"])
    if state["status"] != "working":
        break

print(json.dumps({key: state.get(key) for key in ("status", "media", "files", "question", "error")}, indent=2))
if state["status"] != "done":
    raise RuntimeError(f"Chat is {state['status']}. Open {state['url']}")
```

```javascript Node.js theme={"theme":{"light":"github-light-default","dark":"vesper"}}
import { performance } from "node:perf_hooks";

const token = process.env.KREA_API_KEY;
if (!token) throw new Error("Set your Krea API key");
const api = "https://api.krea.ai";

async function call(method, path, { body, query, timeoutMs = 60_000 } = {}) {
  const url = new URL(`${api}${path}`);
  for (const [key, value] of Object.entries(query ?? {})) url.searchParams.set(key, value);
  const response = await fetch(url, {
    method,
    headers: {
      Authorization: `Bearer ${token}`,
      ...(body ? { "Content-Type": "application/json" } : {}),
    },
    ...(body ? { body: JSON.stringify(body) } : {}),
    signal: AbortSignal.timeout(timeoutMs),
  });
  if (!response.ok) {
    throw new Error(`HTTP ${response.status}: ${await response.text()}`);
  }
  return response.json();
}

const { bots } = await call("GET", "/bots");
if (bots.length === 0) throw new Error("No bots yet. Create one in the Krea app first.");

const start = await call("POST", "/bots/chats", {
  body: {
    bot_id: bots[0].id,
    title: "Coffee mug campaign",
    message: "Create three square product images for a ceramic coffee mug on a neutral studio background. Use no text or logos.",
  },
});
const chatId = start.chat_id;
let cursor = start.cursor;
console.log(start.url);

const deadline = performance.now() + 300_000;
let state;
while (true) {
  if (performance.now() > deadline) {
    throw new Error(
      `Wait budget exhausted; the bot keeps working. Resume with chat_id=${chatId} cursor=${cursor}`,
    );
  }
  state = await call("GET", `/bots/chats/${chatId}/messages`, {
    query: { cursor, wait: 30 },
    timeoutMs: 45_000,
  });
  cursor = state.cursor;
  console.log(state.text);
  if (state.status !== "working") break;
}

const { status, media, files, question, error } = state;
console.log(JSON.stringify({ status, media, files, question, error }, null, 2));
if (status !== "done") throw new Error(`Chat is ${status}. Open ${state.url}`);
```

Python के लिए `pip install requests` से `requests` इंस्टॉल करें। Node.js के लिए Node.js 22+ इस्तेमाल करें और उदाहरण को `example.mjs` के रूप में सेव करें।

ये उदाहरण एक मैसेज भेजते हैं और अधिकतम पाँच मिनट तक पोल करते हैं। HTTP एरर पर ये रुक जाते हैं, और अगर चैट `done` के अलावा किसी स्थिति में खत्म हो तो एरर के साथ बाहर निकलते हैं। ये कभी अपने आप मैसेज दोबारा नहीं भेजते। अगर भेजने की रिक्वेस्ट टाइम आउट हो जाए, तो हो सकता है पहली रिक्वेस्ट ने मैसेज पोस्ट कर दिया हो। उसे उसी `idempotency_key` के साथ दोहराएँ, या दोबारा भेजने से पहले चैट पढ़ें।

इंतज़ार का समय खत्म होने पर भी बॉट काम करता रहता है। बाद में पोलिंग फिर शुरू करने के लिए चैट ID और cursor सेव करें।

### चैट शुरू करना

`POST /bots/chats` `chat_id`, `title`, `message_id`, `cursor`, `bots` और `url` के साथ `201` लौटाता है।

| फ़ील्ड | व्यवहार |
| - | - |
| `bot_id` | `GET /bots` से मिले बॉट का UUID। `bot_id`, `bot_ids` या दोनों भेजें। |
| `bot_ids` | ग्रुप चैट के लिए 20 तक बॉट UUID। [ग्रुप चैट](#group-chats) देखें। |
| `member_ids` | वैकल्पिक, वर्कस्पेस के टीममेट्स की 50 तक यूज़र ID। [ग्रुप चैट](#group-chats) देखें। |
| `title` | वैकल्पिक, 80 कैरेक्टर तक। टाइटल होने पर रिक्वेस्ट अपनी अलग नई चैट खोलती है। एक बॉट, कोई सदस्य नहीं और कोई टाइटल नहीं होने पर यह बॉट के साथ आपकी डायरेक्ट चैट खोलती है, और अगर वह पहले से मौजूद हो तो उसी का दोबारा इस्तेमाल करती है। |
| `message` | वैकल्पिक पहला मैसेज, 8,000 कैरेक्टर तक। यह बॉट का पहला टर्न शुरू करता है। |
| `attachments` | वैकल्पिक, 10 तक। यहाँ अटैचमेंट के लिए `message` ज़रूरी है। [अटैचमेंट](#attachments) देखें। |
| `idempotency_key` | वैकल्पिक, 200 कैरेक्टर तक। [मैसेज सुरक्षित रूप से दोबारा भेजें](#retry-a-send-safely) देखें। |

बिना `message` के खोली गई नई चैट में बॉट हाय कहता है। वह अभिवादन एक बॉट टर्न है और उसी तरह बिल होता है। पहले से मौजूद डायरेक्ट चैट खोलने पर वही चैट लौटती है। बिना `message` के, `message_id` का मान `null` होता है।

### फ़ॉलो-अप मैसेज भेजें

`POST /bots/chats/{chat_id}/messages` किसी मौजूदा चैट में मैसेज पोस्ट करता है और नए `cursor` के साथ `202` लौटाता है:

```bash cURL theme={"theme":{"light":"github-light-default","dark":"vesper"}}
SENT=$(curl --fail-with-body --silent --show-error \
  "https://api.krea.ai/bots/chats/$CHAT_ID/messages" \
  -H "Authorization: Bearer $KREA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "Make a landscape variation of the first image."}')

# Poll with this new cursor.
CURSOR=$(printf '%s' "$SENT" | jq -er '.cursor')
```

`text` में 8,000 कैरेक्टर तक हो सकते हैं। `text`, कम से कम एक अटैचमेंट, या दोनों भेजें।

### मैसेज सुरक्षित रूप से दोबारा भेजें

मैसेज भेजने से एक बिल होने वाला बॉट टर्न शुरू होता है, इसलिए गलती से दो बार भेजने पर दोगुना खर्च होता है। `POST /bots/chats` और `POST /bots/chats/{chat_id}/messages` एक वैकल्पिक `idempotency_key` स्वीकार करते हैं, जो आपकी चुनी हुई स्ट्रिंग है और रिक्वेस्ट को नाम देती है:

```json theme={"theme":{"light":"github-light-default","dark":"vesper"}}
{ "text": "Make a landscape variation of the first image.", "idempotency_key": "order-1842-variation" }
```

अगर कोई रिक्वेस्ट टाइम आउट हो जाए या रिस्पॉन्स खो जाए, तो उसे उसी कुंजी के साथ दोहराएँ। API दोबारा भेजने के बजाय पहली चैट और मैसेज लौटाता है। कुंजियाँ आप तक सीमित होती हैं। हर उस मैसेज के लिए नई कुंजी इस्तेमाल करें जिसे आप भेजना चाहते हैं, एक जैसे टेक्स्ट वाले मैसेज के लिए भी।

### नए मैसेज पोल करें

`GET /bots/chats/{chat_id}/messages` दो क्वेरी पैरामीटर लेता है:

| पैरामीटर | व्यवहार |
| - | - |
| `cursor` | पिछले रिस्पॉन्स का `cursor`, ताकि सिर्फ़ उसके बाद हुआ बदलाव लौटे। इसके बिना, पढ़ना आपके अपने सबसे नए मैसेज के बाद से शुरू होता है। |
| `wait` | रिक्वेस्ट को कितने सेकंड रोके रखना है, जब तक बॉट काम पूरा न करें या कुछ न पूछें, `0` से `30` तक। डिफ़ॉल्ट `0` है, जो तुरंत जवाब देता है। |

अपने HTTP क्लाइंट का टाइमआउट `wait` से ज़्यादा रखें। रिस्पॉन्स `cursor` के बाद की चैट का विवरण देता है:

| फ़ील्ड | मतलब |
| - | - |
| `status` | जब बॉट टर्न के बीच में हो तब `working`, जब बॉट `question` के जवाब का इंतज़ार करे तब `needs_input`, फिर `done`, `failed` या `stopped`। |
| `finished` | `status` के `done`, `failed` या `stopped` होने पर `true`। |
| `timed_out` | `true` जब बॉट के काम करते रहते `wait` खत्म हो जाए, या जब एक रिस्पॉन्स में आने से ज़्यादा कंटेंट अनपढ़ा हो। `cursor` के साथ फिर से पढ़ें। |
| `messages` | नए दिखने वाले मैसेज, सबसे पुराने पहले। हर मैसेज में `id`, `created_at`, `author`, `text`, `attachments` होते हैं, और अगर वह Krea में नहीं लिखा गया तो `via` भी। |
| `text` | बॉट्स के नए मैसेज का टेक्स्ट, जोड़कर। |
| `media` | बॉट्स की पोस्ट की गई इमेज, वीडियो और ऑडियो। हर आइटम में एक `url` होता है और उसमें `uri`, `name`, `mime_type`, `width` और `height` हो सकते हैं। Krea फ़ाइलें साइन किए गए लिंक के रूप में आती हैं। |
| `files` | बॉट्स की पोस्ट की गई दूसरी फ़ाइलें, `media` जैसे ही रूप में। |
| `question` | तब मौजूद जब बॉट जवाब का इंतज़ार कर रहा हो। [सवाल कार्ड](#question-cards) देखें। |
| `error` | `{ code, message }`, तब मौजूद जब `status` का मान `failed` हो। |
| `out_of_compute_bot_ids` | इस चैट में रुके बॉट्स, क्योंकि वर्कस्पेस की कंप्यूट यूनिट खत्म हो गईं। |
| `working`, `progress` | चल रहे टर्न और उनके नए स्टेप। |
| `cursor` | इसे अगली बार पढ़ने में भेजें। |
| `url` | Krea ऐप में चैट का लिंक। |

हर रिस्पॉन्स में सिर्फ़ वही होता है जो `cursor` के बाद नया है। पूरा जवाब चाहिए तो कई बार पढ़कर `text`, `media` और `files` इकट्ठा करें।

इसके बजाय चैट का इतिहास पढ़ने के लिए `GET /bots/chats/{chat_id}` इस्तेमाल करें। यह मैसेज का एक पेज लौटाता है, सबसे नया पेज पहले, `limit` के साथ `1` से `100` तक (डिफ़ॉल्ट `30`)। पीछे के पेज देखने के लिए लौटा हुआ `before` मान `before` के रूप में भेजें।

## अटैचमेंट

`POST /bots/chats` और `POST /bots/chats/{chat_id}/messages` हर मैसेज में 10 तक अटैचमेंट स्वीकार करते हैं। हर अटैचमेंट `{ url, name?, content_type? }` होता है:

```json theme={"theme":{"light":"github-light-default","dark":"vesper"}}
{
  "text": "Use this photo as the reference.",
  "attachments": [
    { "url": "https://example.com/mug.jpg", "name": "mug.jpg", "content_type": "image/jpeg" },
    { "url": "file:550e8400-e29b-41d4-a716-446655440000" }
  ]
}
```

`url` में `http(s)` URL दिया जा सकता है, जैसे [`POST /assets`](https://www.krea.ai/docs/api-reference/assets/upload-an-asset) से मिला एसेट URL, या कोई Krea Files URI `file:<uuid>` जिसका आपके पास एक्सेस हो। `name` और `content_type` 255 कैरेक्टर तक की वैकल्पिक स्ट्रिंग हैं। जो Krea फ़ाइल मौजूद नहीं है या एक्सेस नहीं हो सकती, वह `code: "attachment_not_found"` के साथ `404` लौटाती है।

## सवाल कार्ड

बॉट आगे बढ़ने से पहले रुककर सवाल पूछ सकता है। तब पढ़ने पर `question` के साथ `status: "needs_input"` मिलता है:

```json theme={"theme":{"light":"github-light-default","dark":"vesper"}}
{
  "status": "needs_input",
  "finished": false,
  "question": {
    "id": "toolu_01A2b3C4d5",
    "bot_id": "3f0c8a52-1d7e-4c3b-9a65-2b8e4f1d7c90",
    "kind": "question",
    "text": "Which cup?",
    "options": ["Mug", "Tumbler"],
    "answerable": true
  }
}
```

इसका जवाब `POST /bots/chats/{chat_id}/questions/{question_id}/answer` से दें, फिर जवाब से मिले `cursor` के साथ फिर से पोल करें:

```bash cURL theme={"theme":{"light":"github-light-default","dark":"vesper"}}
curl --fail-with-body --silent --show-error \
  "https://api.krea.ai/bots/chats/$CHAT_ID/questions/$QUESTION_ID/answer" \
  -H "Authorization: Bearer $KREA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"answer": "Mug"}'
```

क्या भेजना है, यह `kind` पर निर्भर करता है:

| `kind` | जवाब |
| - | - |
| `question` | खुला टेक्स्ट, या `options` में से कोई एक हूबहू। जब बॉट ने एक साथ कई सवाल पूछे हों, तो `text` उन्हें नंबर देता है और `options` खाली रहता है। हर सवाल के लिए एक जवाब के साथ, क्रम से, 10 तक, `{ "answers": [...] }` भेजें। |
| `approval` | `Go ahead` या `Not now`। कोई दूसरा टेक्स्ट मंज़ूरी नहीं देता। वह बॉट को फ़ीडबैक के रूप में जाता है। |
| `permission`, `cost_confirm` | `Allow once`, `Always allow` या `Don't allow`। कोई दूसरा टेक्स्ट `400` लौटाता है। |
| दूसरे प्रकार | `answerable` का मान `false` है। सिर्फ़ Krea ऐप की चैट जवाब दे सकती है। चैट का `url` खोलें। |

पहले से जवाब दिए गए सवाल का जवाब देने पर `404` मिलता है।

## ग्रुप चैट

कई बॉट्स वाली, टीममेट्स वाली या टाइटल वाली चैट ग्रुप चैट होती है। इसे `bot_ids` और, ज़रूरत हो तो, `member_ids` के साथ शुरू करें:

```bash cURL theme={"theme":{"light":"github-light-default","dark":"vesper"}}
curl --fail-with-body --silent --show-error \
  "https://api.krea.ai/bots/chats" \
  -H "Authorization: Bearer $KREA_API_KEY" \
  -H "Content-Type: application/json" \
  -d "$(jq -n --arg lead "$LEAD_BOT_ID" --arg second "$SECOND_BOT_ID" --arg teammate "$TEAMMATE_ID" '{
    bot_ids: [$lead, $second],
    member_ids: [$teammate],
    title: "Coffee mug campaign",
    message: "Plan a three-image campaign for a coffee mug."
  }')"
```

नियम वही हैं जो Krea ऐप लागू करता है:

* हर बॉट ऐसा होना चाहिए जिसे आप इस्तेमाल कर सकें, वरना रिक्वेस्ट `404` लौटाती है।
* `member_ids` में हर व्यक्ति वर्कस्पेस में होना चाहिए, वरना रिक्वेस्ट `400` लौटाती है।
* प्राइवेट बॉट सिर्फ़ अपने ओनर के साथ काम करता है। दूसरे लोगों वाली चैट के लिए वर्कस्पेस के साथ शेयर किए गए बॉट चाहिए, वरना रिक्वेस्ट `400` लौटाती है।

टीममेट्स की यूज़र ID उन चैट में `people` के रूप में दिखती हैं जो आप उनके साथ शेयर करते हैं, `GET /bots/chats` और `GET /bots/chats/{chat_id}` से।

### कौन जवाब देता है

`bot_ids` का पहला बॉट चैट की अगुवाई करता है, और `lead_bot_id` उसका नाम बताता है। जिस मैसेज में किसी बॉट का नाम नहीं होता, वह लीड बॉट को जाता है। किसी खास बॉट से बात करने के लिए मैसेज में `@` और उसका नाम लिखें, जैसे `@Thumby make the logo bigger`।

हर रिस्पॉन्स बताता है कि वह किस बॉट से जुड़ा है। हर मैसेज में `author.id` और `author.name` होते हैं, `question` में `bot_id` होता है, और `working` की हर एंट्री में `bot_id` होता है। पोलिंग में `status` तब तक `working` रहता है जब तक चैट के सभी बॉट रुक न जाएँ।

### बॉट्स और लोगों को जोड़ें और हटाएँ

`POST /bots/chats/{chat_id}/members` `bot_ids`, `member_ids` या दोनों लेता है, और बताता है कि अब चैट में कौन है: `chat_id`, `title`, `kind`, `lead_bot_id`, `bots`, `people` और `url`। चैट में कोई भी जोड़ सकता है। डायरेक्ट चैट में जोड़ने से वह ग्रुप चैट बन जाती है। चैट में पहले से मौजूद बॉट और लोग वैसे ही रहते हैं।

```bash cURL theme={"theme":{"light":"github-light-default","dark":"vesper"}}
curl --fail-with-body --silent --show-error \
  "https://api.krea.ai/bots/chats/$CHAT_ID/members" \
  -H "Authorization: Bearer $KREA_API_KEY" \
  -H "Content-Type: application/json" \
  -d "$(jq -n --arg bot "$BOT_ID" '{bot_ids: [$bot]}')"
```

हटाने के लिए कोई बॉडी नहीं चाहिए और यह `{ "chat_id": "...", "removed": { "kind": "bot", "id": "..." }, "left": false }` लौटाता है:

| रिक्वेस्ट | कौन कॉल कर सकता है |
| - | - |
| `DELETE /bots/chats/{chat_id}/bots/{bot_id}` | चैट शुरू करने वाला व्यक्ति, या बॉट का ओनर। |
| `DELETE /bots/chats/{chat_id}/members/{member_id}` | चैट शुरू करने वाला व्यक्ति, उसमें मौजूद किसी और के लिए। |
| `DELETE /bots/chats/{chat_id}/members/{your_user_id}` | चैट शुरू करने वाले व्यक्ति को छोड़कर कोई भी। आप चैट छोड़ देते हैं, और `left` का मान `true` होता है। |

बाकी सभी को `403` (`forbidden`) मिलता है। चैट शुरू करने वाला व्यक्ति उसे छोड़ नहीं सकता, और डायरेक्ट चैट का बॉट हटाया नहीं जा सकता; दोनों `400` लौटाते हैं। इसके बजाय चैट डिलीट करें। किसी बॉट या व्यक्ति को हटाने से वह काम रुक जाता है जो बॉट कर रहा था, या जो बॉट्स उस व्यक्ति के लिए कर रहे थे।

### चैट डिलीट करें

`DELETE /bots/chats/{chat_id}` डायरेक्ट या ग्रुप चैट को उसमें मौजूद सभी लोगों के लिए डिलीट करता है और `{ "chat_id": "...", "deleted": true }` लौटाता है। सिर्फ़ चैट शुरू करने वाला व्यक्ति या वर्कस्पेस एडमिन इसे डिलीट कर सकता है; चैट में बाकी सभी को `403` (`forbidden`) मिलता है। चैट में चल रहा हर बॉट टर्न और हेल्पर रुक जाता है। इसके बाद डिलीट की गई चैट `404` लौटाती है, और उसी बॉट के साथ डायरेक्ट चैट दोबारा खोलने पर नई चैट शुरू होती है।

```bash cURL theme={"theme":{"light":"github-light-default","dark":"vesper"}}
curl --fail-with-body --silent --show-error -X DELETE \
  "https://api.krea.ai/bots/chats/$CHAT_ID" \
  -H "Authorization: Bearer $KREA_API_KEY"
```

## टर्न रोकें

`POST /bots/chats/{chat_id}/stop` चैट में काम कर रहे हर बॉट और उनके हेल्पर को रोकता है। बॉडी के दोनों फ़ील्ड वैकल्पिक हैं:

| फ़ील्ड | व्यवहार |
| - | - |
| `bot_id` | सिर्फ़ इस बॉट को रोकें। ग्रुप चैट में बाकी बॉट काम करते रहते हैं, और जब तक वे काम करते हैं, रिस्पॉन्स में `status: "working"` बना रहता है। |
| `cursor` | जिस cursor से पढ़ना है, जैसे पोलिंग में। |

```bash cURL theme={"theme":{"light":"github-light-default","dark":"vesper"}}
curl --fail-with-body --silent --show-error \
  "https://api.krea.ai/bots/chats/$CHAT_ID/stop" \
  -H "Authorization: Bearer $KREA_API_KEY" \
  -H "Content-Type: application/json" \
  -d "$(jq -n --arg cursor "$CURSOR" '{cursor: $cursor}')"
```

रिस्पॉन्स चैट की स्थिति है, पोलिंग जैसे ही रूप में, आम तौर पर `status: "stopped"` और `finished: true` के साथ।

## कंप्यूट यूनिट खत्म होना और यूसेज लिमिट

वर्कस्पेस में कंप्यूट यूनिट न बचने पर, या यूसेज लिमिट खत्म होने पर भी, मैसेज भेजने पर `202` मिलता है। टर्न नहीं चलता। रोक तब दिखती है जब आप चैट पढ़ते हैं:

```json theme={"theme":{"light":"github-light-default","dark":"vesper"}}
{
  "status": "failed",
  "finished": true,
  "error": { "code": "out_of_compute", "message": "..." },
  "out_of_compute_bot_ids": ["3f0c8a52-1d7e-4c3b-9a65-2b8e4f1d7c90"]
}
```

| `error.code` | मतलब |
| - | - |
| `out_of_compute` | वर्कस्पेस की कंप्यूट यूनिट खत्म हो गईं। रुके हुए बॉट `out_of_compute_bot_ids` में दिए गए हैं। |
| `bot_usage_limit` | बॉट अपनी यूसेज लिमिट तक पहुँच गया। |
| `chat_usage_limit` | चैट अपनी यूसेज लिमिट तक पहुँच गई। |

ये तीनों बिलिंग की रोक हैं, गड़बड़ी नहीं। दूसरे कोड बताते हैं कि टर्न फ़ेल हुआ: `refused`, `busy`, `timeout`, `provider`, `server`, `context`, `claude_billing` और `unknown`।

कंप्यूट यूनिट जोड़ने के बाद, रुके बॉट्स को फिर चालू करने के लिए `POST /bots/chats/{chat_id}/retry` कॉल करें, या नया मैसेज भेजें। Retry को बॉडी नहीं चाहिए और बॉट फिर चालू होने पर यह `{ "retried": true, "out_of_compute": false }` लौटाता है। जब तक बैलेंस खाली है, यह कुछ नहीं करता और `{ "retried": false, "out_of_compute": true }` लौटाता है। Retry के बाद फिर से पोल करें।

## एरर

एंडपॉइंट एरर `{ "error": "...", "code": "..." }` इस्तेमाल करते हैं। सिर्फ़ `error` ज़रूरी है। मैसेज स्वीकार होने के बाद फ़ेल होने वाला टर्न इसके बजाय सफल पढ़ाई में `status: "failed"` के रूप में दिखता है।

| HTTP स्टेटस | मतलब |
| - | - |
| `400` | गलत JSON बॉडी, या ऐसी रिक्वेस्ट जिसे चैट मना करती है (`bad_request`), जैसे ऐसा cursor जो चैट ने नहीं लौटाया या ऐसा जवाब जो सवाल से मेल नहीं खाता। |
| `401` | ऑथेंटिकेशन मौजूद नहीं या अमान्य। |
| `403` | Bots वर्कस्पेस के प्लान में शामिल नहीं है (`entitlement_denied`, `required_plan` के साथ), या इस अकाउंट के लिए खुला नहीं है (`bots_unavailable`)। या आप चैट में यह बदलाव नहीं कर सकते (`forbidden`), जैसे ऐसा बॉट हटाना जो न आपका है और न आपने अपनी शुरू की गई चैट में लाया। |
| `404` | बॉट, चैट या सवाल मौजूद नहीं या एक्सेस नहीं हो सकता (`not_found`), इसमें वे चैट भी शामिल हैं जिनमें आप नहीं हैं। या Krea फ़ाइल अटैचमेंट मौजूद नहीं या एक्सेस नहीं हो सकता (`attachment_not_found`)। |
| `409` | रिक्वेस्ट के दौरान चैट बदल गई, या कोई stop अभी पूरा नहीं हुआ (`conflict`)। थोड़ी देर में फिर से कोशिश करें। |
| `422` | अमान्य इनपुट: `{ "error": "Validation failed", "details": [...] }`। अनजान बॉडी फ़ील्ड अस्वीकार किए जाते हैं। |
| `429` | बहुत ज़्यादा रिक्वेस्ट (`rate_limited`)। |

`429` लिमिट सिर्फ़ बेकाबू क्लाइंट से बचाव के लिए है: हर यूज़र के लिए प्रति मिनट 60 राइट और 600 रीड। राइट में शुरू करना, भेजना, जवाब देना, रोकना, दोबारा चलाना, डिलीट करना, और बॉट्स और लोगों को जोड़ना या हटाना शामिल है। `wait=30` के साथ लॉन्ग पोलिंग रीड लिमिट से काफ़ी नीचे रहती है।

## इस वर्ज़न में नहीं

* बॉट बनाना, एडिट करना या डिलीट करना, और बॉट सेटिंग्स। बॉट्स को Krea ऐप में मैनेज करें।
* vault।
* वेबहुक और स्ट्रीमिंग। इसके बजाय `wait` के साथ पोल करें।
* चैट का नाम बदलना या उसे आर्काइव करना। यह Krea ऐप में करें।


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