{
  "info": {
    "name": "Noqte OpenAI-compatible API",
    "description": "API سازگار با OpenAI نقطه برای مدل‌های زبانی، با کردیت کیف پول. متغیر apiKey را با کلید sk-noqte-… خود پر کنید و Send بزنید؛ baseUrl و model از پیش تنظیم شده‌اند. مسیر پیشنهادی: فهرست مدل‌ها، گفتگوی ساده، stream، فراخوانی ابزار.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "auth": {
    "type": "bearer",
    "bearer": [
      {
        "key": "token",
        "value": "{{apiKey}}",
        "type": "string"
      }
    ]
  },
  "variable": [
    {
      "key": "baseUrl",
      "value": "https://api.noqte.ai/v1",
      "type": "string"
    },
    {
      "key": "apiKey",
      "value": "",
      "type": "string"
    },
    {
      "key": "model",
      "value": "noqte-1.2",
      "type": "string"
    },
    {
      "key": "toolCallId",
      "value": "",
      "type": "string"
    },
    {
      "key": "toolCallName",
      "value": "",
      "type": "string"
    },
    {
      "key": "toolCallArguments",
      "value": "",
      "type": "string"
    },
    {
      "key": "idempotencyKey",
      "value": "",
      "type": "string"
    },
    {
      "key": "idempotencyFirstId",
      "value": "",
      "type": "string"
    }
  ],
  "item": [
    {
      "name": "حساب و مدل‌ها",
      "description": "فهرست مدل‌ها با قیمت، و موجودی کیف پول.",
      "item": [
        {
          "name": "فهرست مدل‌ها",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test(\"status 200\", () => pm.response.to.have.status(200));",
                  "const body = pm.response.json();",
                  "pm.test(\"is a list of models\", () => {",
                  "  pm.expect(body.object).to.eql(\"list\");",
                  "  pm.expect(body.data).to.be.an(\"array\").that.is.not.empty;",
                  "  pm.expect(body.data[0]).to.include.keys(\"id\", \"endpoints\", \"pricing\");",
                  "});"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{apiKey}}"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/models",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "models"
              ]
            },
            "description": "GET /v1/models: مدل‌هایی که این کلید می‌تواند صدا بزند، با قیمت هر کدام. مدل‌هایی که در endpoints آن‌ها chat/completions آمده با این API کار می‌کنند؛ شناسهٔ دلخواه را در متغیر model بگذارید."
          },
          "response": [
            {
              "name": "200 example",
              "originalRequest": {
                "method": "GET",
                "header": [
                  {
                    "key": "Authorization",
                    "value": "Bearer {{apiKey}}"
                  }
                ],
                "url": {
                  "raw": "{{baseUrl}}/models",
                  "host": [
                    "{{baseUrl}}"
                  ],
                  "path": [
                    "models"
                  ]
                }
              },
              "status": "200",
              "code": 200,
              "_postman_previewlanguage": "json",
              "header": [
                {
                  "key": "Content-Type",
                  "value": "application/json"
                }
              ],
              "body": "{\n  \"object\": \"list\",\n  \"data\": [\n    {\n      \"id\": \"noqte-1.2\",\n      \"object\": \"model\",\n      \"created\": 1794731582,\n      \"owned_by\": \"noqte\",\n      \"label\": \"Noqte 1.2\",\n      \"endpoints\": [\n        \"chat/completions\"\n      ],\n      \"pricing\": {\n        \"unit\": \"tokens\"\n      }\n    }\n  ]\n}"
            }
          ]
        },
        {
          "name": "موجودی کیف پول",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test(\"status 200\", () => pm.response.to.have.status(200));",
                  "const body = pm.response.json();",
                  "pm.test(\"has the wallet balance\", () => {",
                  "  pm.expect(body.billing).to.eql(\"credits\");",
                  "  pm.expect(body).to.have.property(\"balance_credits\");",
                  "});"
                ]
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{apiKey}}"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/usage",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "usage"
              ]
            },
            "description": "GET /v1/usage: موجودی کردیت کیف پول در balance_credits."
          },
          "response": [
            {
              "name": "200 example",
              "originalRequest": {
                "method": "GET",
                "header": [
                  {
                    "key": "Authorization",
                    "value": "Bearer {{apiKey}}"
                  }
                ],
                "url": {
                  "raw": "{{baseUrl}}/usage",
                  "host": [
                    "{{baseUrl}}"
                  ],
                  "path": [
                    "usage"
                  ]
                }
              },
              "status": "200",
              "code": 200,
              "_postman_previewlanguage": "json",
              "header": [
                {
                  "key": "Content-Type",
                  "value": "application/json"
                }
              ],
              "body": "{\n  \"billing\": \"credits\",\n  \"balance_credits\": 1250.5\n}"
            }
          ]
        }
      ]
    },
    {
      "name": "گفتگو",
      "description": "پاسخ کامل، stream و ورودی تصویر.",
      "item": [
        {
          "name": "گفتگوی ساده",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test(\"status 200\", () => pm.response.to.have.status(200));",
                  "const body = pm.response.json();",
                  "pm.test(\"has a choice with a message\", () => {",
                  "  pm.expect(body.choices).to.be.an(\"array\").that.is.not.empty;",
                  "  pm.expect(body.choices[0].message).to.be.an(\"object\");",
                  "});",
                  "pm.test(\"model is the id that was sent\", () => pm.expect(body.model).to.eql(pm.variables.replaceIn(\"{{model}}\")));"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{apiKey}}"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"model\": \"{{model}}\",\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"سلام! یک جمله دربارهٔ تهران بنویس.\"\n    }\n  ],\n  \"max_tokens\": 300\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/chat/completions",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "chat",
                "completions"
              ]
            },
            "description": "POST /v1/chat/completions: یک پیام و پاسخ کامل در یک JSON."
          },
          "response": [
            {
              "name": "200 example",
              "originalRequest": {
                "method": "POST",
                "header": [
                  {
                    "key": "Authorization",
                    "value": "Bearer {{apiKey}}"
                  },
                  {
                    "key": "Content-Type",
                    "value": "application/json"
                  }
                ],
                "url": {
                  "raw": "{{baseUrl}}/chat/completions",
                  "host": [
                    "{{baseUrl}}"
                  ],
                  "path": [
                    "chat",
                    "completions"
                  ]
                }
              },
              "status": "200",
              "code": 200,
              "_postman_previewlanguage": "json",
              "header": [
                {
                  "key": "Content-Type",
                  "value": "application/json"
                }
              ],
              "body": "{\n  \"id\": \"nq_e13651caa3c4c20201ca1b5b\",\n  \"object\": \"chat.completion\",\n  \"created\": 1794731582,\n  \"model\": \"noqte-1.2\",\n  \"choices\": [\n    {\n      \"index\": 0,\n      \"finish_reason\": \"stop\",\n      \"message\": {\n        \"role\": \"assistant\",\n        \"content\": \"تهران پایتخت ایران است و شهری پرجنب‌وجوش با تاریخ و فرهنگی غنی است.\"\n      }\n    }\n  ],\n  \"usage\": {\n    \"prompt_tokens\": 37,\n    \"completion_tokens\": 21,\n    \"total_tokens\": 58\n  }\n}"
            }
          ]
        },
        {
          "name": "گفتگو با stream",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test(\"status 200\", () => pm.response.to.have.status(200));",
                  "pm.test(\"is an event stream\", () => pm.expect(pm.response.headers.get(\"Content-Type\")).to.include(\"text/event-stream\"));",
                  "pm.test(\"ends with [DONE]\", () => pm.expect(pm.response.text()).to.include(\"data: [DONE]\"));"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{apiKey}}"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"model\": \"{{model}}\",\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"از ۱ تا ۵ بشمار\"\n    }\n  ],\n  \"stream\": true,\n  \"stream_options\": {\n    \"include_usage\": true\n  }\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/chat/completions",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "chat",
                "completions"
              ]
            },
            "description": "همان مسیر با stream: true. پاسخ رویدادهای data: است و با data: [DONE] تمام می‌شود؛ آخرین تکه usage دارد و choices آن خالی است."
          },
          "response": []
        },
        {
          "name": "ورودی تصویر",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test(\"status 200\", () => pm.response.to.have.status(200));",
                  "const body = pm.response.json();",
                  "pm.test(\"has a choice with a message\", () => {",
                  "  pm.expect(body.choices).to.be.an(\"array\").that.is.not.empty;",
                  "  pm.expect(body.choices[0].message).to.be.an(\"object\");",
                  "});",
                  "pm.test(\"model is the id that was sent\", () => pm.expect(body.model).to.eql(pm.variables.replaceIn(\"{{model}}\")));"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{apiKey}}"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"model\": \"{{model}}\",\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": [\n        {\n          \"type\": \"text\",\n          \"text\": \"این تصویر چه رنگی است؟\"\n        },\n        {\n          \"type\": \"image_url\",\n          \"image_url\": {\n            \"url\": \"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAAKklEQVR42mO4o6ZGU8QwasGoBaMWjFowasGoBaMWjFowasGoBaMWDBULAIjyoD2JhwFtAAAAAElFTkSuQmCC\"\n          }\n        }\n      ]\n    }\n  ],\n  \"max_tokens\": 100\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/chat/completions",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "chat",
                "completions"
              ]
            },
            "description": "بخشی با type: image_url در content. نمونه یک مربع قرمز ۳۲ پیکسلی را به‌صورت data URL (base64) می‌فرستد تا بدون فایل کار کند؛ به‌جای آن لینک https یک تصویر هم می‌توانید بگذارید. پشتیبانی از تصویر به مدل انتخابی بستگی دارد."
          },
          "response": []
        }
      ]
    },
    {
      "name": "فراخوانی ابزار",
      "description": "دو قدم: مدل ابزار را صدا می‌زند، شما نتیجه را برمی‌گردانید.",
      "item": [
        {
          "name": "۱. درخواست ابزار از مدل",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test(\"status 200\", () => pm.response.to.have.status(200));",
                  "const message = pm.response.json().choices[0].message;",
                  "pm.test(\"model asked for a tool\", () => pm.expect(message.tool_calls).to.be.an(\"array\").that.is.not.empty);",
                  "const call = (message.tool_calls || [])[0];",
                  "if (call) {",
                  "  pm.collectionVariables.set(\"toolCallId\", call.id);",
                  "  pm.collectionVariables.set(\"toolCallName\", call.function.name);",
                  "  // arguments is a JSON string: keep it escaped so it fits inside the quotes of the next body.",
                  "  pm.collectionVariables.set(\"toolCallArguments\", JSON.stringify(call.function.arguments).slice(1, -1));",
                  "}"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{apiKey}}"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"model\": \"{{model}}\",\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"هوای تهران چطور است؟\"\n    }\n  ],\n  \"tools\": [\n    {\n      \"type\": \"function\",\n      \"function\": {\n        \"name\": \"get_weather\",\n        \"description\": \"Get the weather for a city\",\n        \"parameters\": {\n          \"type\": \"object\",\n          \"properties\": {\n            \"city\": {\n              \"type\": \"string\"\n            }\n          },\n          \"required\": [\n            \"city\"\n          ]\n        }\n      }\n    }\n  ],\n  \"tool_choice\": \"auto\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/chat/completions",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "chat",
                "completions"
              ]
            },
            "description": "مدل به‌جای پاسخ، tool_calls برمی‌گرداند. اسکریپت تست شناسه، نام و آرگومان‌های فراخوانی را در متغیرهای toolCallId، toolCallName و toolCallArguments می‌گذارد تا درخواست بعدی آن‌ها را بفرستد."
          },
          "response": []
        },
        {
          "name": "۲. برگرداندن نتیجهٔ ابزار",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "if (!pm.collectionVariables.get(\"toolCallId\")) {",
                  "  throw new Error(\"Send request «۱. درخواست ابزار از مدل» first: it stores the tool call.\");",
                  "}"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test(\"status 200\", () => pm.response.to.have.status(200));",
                  "const body = pm.response.json();",
                  "pm.test(\"has a choice with a message\", () => {",
                  "  pm.expect(body.choices).to.be.an(\"array\").that.is.not.empty;",
                  "  pm.expect(body.choices[0].message).to.be.an(\"object\");",
                  "});",
                  "pm.test(\"model is the id that was sent\", () => pm.expect(body.model).to.eql(pm.variables.replaceIn(\"{{model}}\")));",
                  "pm.test(\"answers in text\", () => pm.expect(body.choices[0].message.content).to.be.a(\"string\").that.is.not.empty);"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{apiKey}}"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"model\": \"{{model}}\",\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"هوای تهران چطور است؟\"\n    },\n    {\n      \"role\": \"assistant\",\n      \"content\": null,\n      \"tool_calls\": [\n        {\n          \"id\": \"{{toolCallId}}\",\n          \"type\": \"function\",\n          \"function\": {\n            \"name\": \"{{toolCallName}}\",\n            \"arguments\": \"{{toolCallArguments}}\"\n          }\n        }\n      ]\n    },\n    {\n      \"role\": \"tool\",\n      \"tool_call_id\": \"{{toolCallId}}\",\n      \"content\": \"آفتابی، ۲۱ درجه\"\n    }\n  ],\n  \"tools\": [\n    {\n      \"type\": \"function\",\n      \"function\": {\n        \"name\": \"get_weather\",\n        \"description\": \"Get the weather for a city\",\n        \"parameters\": {\n          \"type\": \"object\",\n          \"properties\": {\n            \"city\": {\n              \"type\": \"string\"\n            }\n          },\n          \"required\": [\n            \"city\"\n          ]\n        }\n      }\n    }\n  ]\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/chat/completions",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "chat",
                "completions"
              ]
            },
            "description": "پیام assistant با همان tool_calls و بعد پیام role: tool با همان tool_call_id. اول درخواست «۱» را بفرستید تا متغیرها پر شوند."
          },
          "response": []
        }
      ]
    },
    {
      "name": "تکرار امن و خطا",
      "description": "Idempotency-Key و شکل خطا.",
      "item": [
        {
          "name": "درخواست با Idempotency-Key",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "if (!pm.collectionVariables.get(\"idempotencyKey\")) {",
                  "  pm.collectionVariables.set(\"idempotencyKey\", pm.variables.replaceIn(\"{{$guid}}\"));",
                  "  pm.collectionVariables.set(\"idempotencyFirstId\", \"\");",
                  "}"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test(\"status 200\", () => pm.response.to.have.status(200));",
                  "const body = pm.response.json();",
                  "pm.test(\"has a choice with a message\", () => {",
                  "  pm.expect(body.choices).to.be.an(\"array\").that.is.not.empty;",
                  "  pm.expect(body.choices[0].message).to.be.an(\"object\");",
                  "});",
                  "pm.test(\"model is the id that was sent\", () => pm.expect(body.model).to.eql(pm.variables.replaceIn(\"{{model}}\")));",
                  "const first = pm.collectionVariables.get(\"idempotencyFirstId\");",
                  "if (first) {",
                  "  pm.test(\"replay returns the stored answer\", () => pm.expect(body.id).to.eql(first));",
                  "} else {",
                  "  pm.collectionVariables.set(\"idempotencyFirstId\", body.id);",
                  "}"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{apiKey}}"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "Idempotency-Key",
                "value": "{{idempotencyKey}}",
                "description": "برای هر درخواست منطقی یک شناسهٔ یکتا؛ در تلاش دوباره همان مقدار و همان بدنه."
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"model\": \"{{model}}\",\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"یک عدد تصادفی بین ۱ و ۱۰۰ بگو.\"\n    }\n  ],\n  \"max_tokens\": 50\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/chat/completions",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "chat",
                "completions"
              ]
            },
            "description": "دو بار Send بزنید: بار دوم همان پاسخ بار اول برمی‌گردد و هزینهٔ دوباره ندارد (فقط برای درخواست غیر stream). تغییر بدنه با همان شناسه 409 می‌دهد. برای درخواست تازه، متغیرهای idempotencyKey و idempotencyFirstId را خالی کنید."
          },
          "response": []
        },
        {
          "name": "مدل ناموجود (خطای نمونه)",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test(\"status 404\", () => pm.response.to.have.status(404));",
                  "const error = pm.response.json().error;",
                  "pm.test(\"OpenAI error shape\", () => {",
                  "  pm.expect(error.code).to.eql(\"model_not_found\");",
                  "  pm.expect(error.type).to.eql(\"invalid_request_error\");",
                  "  pm.expect(error.message).to.be.a(\"string\");",
                  "});"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{apiKey}}"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"model\": \"not-a-real-model\",\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"سلام\"\n    }\n  ]\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/chat/completions",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "chat",
                "completions"
              ]
            },
            "description": "عمداً خطا می‌دهد تا شکل خطا را ببینید: 404 با error.code برابر model_not_found. درخواستی که رد شود هزینه‌ای ندارد."
          },
          "response": [
            {
              "name": "404 example",
              "originalRequest": {
                "method": "POST",
                "header": [
                  {
                    "key": "Authorization",
                    "value": "Bearer {{apiKey}}"
                  },
                  {
                    "key": "Content-Type",
                    "value": "application/json"
                  }
                ],
                "url": {
                  "raw": "{{baseUrl}}/chat/completions",
                  "host": [
                    "{{baseUrl}}"
                  ],
                  "path": [
                    "chat",
                    "completions"
                  ]
                }
              },
              "status": "404",
              "code": 404,
              "_postman_previewlanguage": "json",
              "header": [
                {
                  "key": "Content-Type",
                  "value": "application/json"
                }
              ],
              "body": "{\n  \"error\": {\n    \"message\": \"The model is not enabled.\",\n    \"type\": \"invalid_request_error\",\n    \"param\": null,\n    \"code\": \"model_not_found\"\n  }\n}"
            }
          ]
        }
      ]
    }
  ]
}