← AhoosAI→ اهوس‌ای‌آی

API reference

The AhoosAI API serves the Nimbus 2 Apex model in the format of OpenAI's Chat Completions API. Existing OpenAI client libraries work with it once the base URL and the key are changed.

Base URL

https://ahoos-ai.site/services/api/v1
MethodPathPurpose
GET/modelsLists the available models.
POST/chat/completionsGenerates a response to a conversation.

Authentication

Every request to /chat/completions must carry an API key in the Authorization header:

Authorization: Bearer nim_YOUR_KEY

Keys are created and revoked on the platform after signing in. A missing, unknown or revoked key is answered with status 401.

Example

With the official OpenAI library for Python:

from openai import OpenAI

client = OpenAI(base_url="https://ahoos-ai.site/services/api/v1", api_key="nim_YOUR_KEY")

response = client.chat.completions.create(
    model="nimbus-2-apex",
    messages=[{"role": "user", "content": "Explain recursion in two sentences."}],
    extra_body={"thinking_level": 5},
)
print(response.choices[0].message.content)

Request

POST /chat/completions accepts a JSON body of at most 16 MB.

FieldTypeDescription
messagesarrayRequired. The conversation. Roles: system, user, assistant, tool. The last message must be user or tool. Content is a string or an array of text parts.
modelstringOptional. If given, it must be nimbus-2-apex.
streambooleanStreams the response as server-sent events. Default false.
max_tokensintegerThe maximum length of the answer, from 16 to 8,192 tokens. Default 4,096. max_completion_tokens is accepted as well. The reasoning has its own budget, set by the reasoning level.
thinking_levelintegerReasoning level, 1 to 20. Default 5. Higher levels reason longer before answering.
reasoning_effortstringAn alternative to thinking_level: minimal (1), low (3), medium (6) or high (12).
temperature_dialintegerTemperature, 1 to 10. Default 5. Lower values give more predictable answers.
temperaturenumberAn alternative to temperature_dial: the value is multiplied by 5 and rounded (1.0 becomes 5).
toolsarrayFunctions the model may call, in OpenAI's format. See Tools.
tool_choicestring or objectauto (default), none, required, or {"type": "function", "function": {"name": "..."}}.
nimbus_toolsarrayTools that run on AhoosAI's side: web_search, fetch_url. See Web search.
web_search_optionsobjectTurns on web search, as in OpenAI's API. Its contents are not used.

Other fields of OpenAI's format are accepted and ignored. Audio and files other than images are not supported.

Response

{
  "id": "chatcmpl-...",
  "object": "chat.completion",
  "model": "nimbus-2-apex",
  "choices": [{
    "index": 0,
    "finish_reason": "stop",
    "message": {
      "role": "assistant",
      "content": "The answer.",
      "reasoning_content": "The reasoning that preceded it."
    }
  }],
  "usage": {"prompt_tokens": 120, "completion_tokens": 310, "total_tokens": 430},
  "nimbus": {"thinking_level": 5, "temperature": 5, "think_words": 160, "forced_close": false, "tokens_per_second": 28.4}
}
  • reasoning_content holds the model's reasoning; content holds the answer.
  • finish_reason is stop, length (the answer reached max_tokens or the context limit) or tool_calls.
  • nimbus.forced_close is true when the reasoning reached the ceiling of its level and was closed.

Streaming

With "stream": true the response is a sequence of server-sent events, each a line data: {...}:

  • choices[0].delta.reasoning_content: the next part of the reasoning.
  • choices[0].delta.content: the next part of the answer.
  • choices[0].delta.tool_calls: a tool call, sent complete in one event.
  • The last event carries finish_reason, usage and nimbus; the stream then ends with data: [DONE].

An error during the stream is sent as data: {"error": {"message": "...", "type": "..."}}.

Tools

Tools follow OpenAI's function-calling format. When the model decides to use a tool, the response ends with finish_reason: "tool_calls" and one call in message.tool_calls. Run the function, add the assistant message and a tool message with the result to the conversation, and send it again:

{"role": "tool", "tool_call_id": "call_...", "content": "the function's result"}

The arguments of every call match the parameter schema of the tool. At most one call is returned per response.

Images

A user message may include images as OpenAI's image_url parts, given as a data: URL (PNG, JPEG, WebP or GIF) or an https address:

{"role": "user", "content": [
  {"type": "text", "text": "What does this chart show?"},
  {"type": "image_url", "image_url": {"url": "data:image/png;base64,..."}}
]}

The model reads text only. Each image is first read by AhoosAI's image module, apex-imagexo-v1, which turns its text (read by OCR, in English and Persian) and its shapes (position, size and colour) into an XML scene; the model answers from that scene. It reads documents, screenshots, tables, forms, charts and diagrams well; it does not see the content of photographs, such as faces or objects.

  • Up to 4 images per request, each up to 8 MB.
  • The scenes of the last message's images are returned in nimbus.images. Send them as text in later turns instead of the image, so the image is not read again.

Agents and tools

When a request carries your own tools, the model works as an agent: at every step it either calls one of your tools or replies, and the call's arguments follow the tool's parameter schema. To help it choose, tools with common names for writing, editing and reading files, listing files and running commands (for example Write, Edit, Read, Glob, Bash) are pointed out to it, and a project folder named in your system message (such as Primary working directory: ...) is given to it as the place for files. Keep the list of tools to what the task needs: a long list costs context and makes the right choice harder.

"nimbus_tools": ["web_search", "fetch_url"] (or web_search_options) lets the model search the web and read pages before it answers. These tools run on AhoosAI's servers; their calls are not returned to you, and the answer continues with their results. An answer may use up to six such steps.

  • In a stream, each step is reported in a nimbus_tool field: {"id", "name", "arguments", "status"}, where status is running, done or error. A finished search also lists its results (title, url, snippet).
  • In a non-streamed response, the finished steps are listed in nimbus.tools.

Search queries are sent to public search engines, and pages are fetched from their own sites.

Errors

Errors use OpenAI's format: {"error": {"message": "...", "type": "..."}}.

StatusTypeMeaning
400invalid_request_errorThe body is not valid JSON, has no messages, or does not end with a user or tool message.
401authentication_errorThe key is missing, unknown or revoked.
404invalid_request_errorUnknown endpoint or model.
405invalid_request_errorThe method is not allowed.
413invalid_request_errorThe body is larger than 16 MB.
429rate_limit_errorThe key's limit for the period is used up. The error includes used, limit and period.
502, 503engine_error, engine_unavailableThe model could not answer. Retry later.

Context and timing

  • A request may use up to 40,960 tokens in total: the conversation, the tool definitions, the reasoning and the answer. When it is longer, the descriptions of the tools are shortened first and then the oldest exchanges are left out; if the last exchange alone does not fit, the request fails.
  • The model starts on demand. After a period without requests, the first response can take up to two minutes.
  • Requests are answered one at a time; others wait for their turn.
  • A long request can take a minute before its first token. While a streamed response waits, the server sends comment lines (: keepalive) every few seconds, which SSE clients ignore.

مرجع API

API اهوس‌ای‌آی مدل نیمبوس ۲ ایپکس را در قالب Chat Completions شرکت OpenAI ارائه می‌کند. کتابخانه‌های موجود OpenAI پس از تغییر نشانی پایه و کلید، بدون تغییر دیگری با آن کار می‌کنند.

نشانی پایه

https://ahoos-ai.site/services/api/v1
روشمسیرکاربرد
GET/modelsفهرست مدل‌های در دسترس
POST/chat/completionsتولید پاسخ برای یک گفتگو

احراز هویت

هر درخواست به /chat/completions باید یک کلید API را در سرآیند Authorization همراه داشته باشد:

Authorization: Bearer nim_YOUR_KEY

کلیدها پس از ورود به حساب، در پلتفرم ساخته و باطل می‌شوند. به درخواستی که کلید نداشته باشد یا کلید آن ناشناخته یا باطل‌شده باشد، با کد وضعیت 401 پاسخ داده می‌شود.

نمونه

با کتابخانهٔ رسمی OpenAI برای پایتون:

from openai import OpenAI

client = OpenAI(base_url="https://ahoos-ai.site/services/api/v1", api_key="nim_YOUR_KEY")

response = client.chat.completions.create(
    model="nimbus-2-apex",
    messages=[{"role": "user", "content": "بازگشت (recursion) را در دو جمله توضیح بده."}],
    extra_body={"thinking_level": 5},
)
print(response.choices[0].message.content)

درخواست

POST /chat/completions یک بدنهٔ JSON با حجم حداکثر ۱۶ مگابایت می‌پذیرد.

فیلدنوعتوضیح
messagesآرایهالزامی. پیام‌های گفتگو با نقش‌های system، user، assistant و tool. آخرین پیام باید از نوع user یا tool باشد. محتوا یک رشته یا آرایه‌ای از بخش‌های متنی است.
modelرشتهاختیاری. در صورت ارسال، باید nimbus-2-apex باشد.
streamبولیپاسخ را به‌صورت رویدادهای server-sent ارسال می‌کند. پیش‌فرض false.
max_tokensعدد صحیحبیشترین طول پاسخ، از ۱۶ تا ۸۱۹۲ توکن. پیش‌فرض ۴۰۹۶. فیلد max_completion_tokens نیز پذیرفته می‌شود. استدلال مدل سهمیهٔ جداگانه‌ای دارد که سطح استدلال آن را تعیین می‌کند.
thinking_levelعدد صحیحسطح استدلال، از ۱ تا ۲۰. پیش‌فرض ۵. در سطوح بالاتر، مدل پیش از پاسخ طولانی‌تر استدلال می‌کند.
reasoning_effortرشتهجایگزین thinking_level: مقدار minimal (۱)، low (۳)، medium (۶) یا high (۱۲).
temperature_dialعدد صحیحدما، از ۱ تا ۱۰. پیش‌فرض ۵. مقادیر کمتر پاسخ‌های قابل‌پیش‌بینی‌تری می‌دهند.
temperatureعددجایگزین temperature_dial: مقدار در ۵ ضرب و گرد می‌شود (۱٫۰ برابر ۵ است).
toolsآرایهتوابعی که مدل می‌تواند فراخوانی کند، در قالب OpenAI. بخش ابزارها را ببینید.
tool_choiceرشته یا شیءauto (پیش‌فرض)، none، required یا {"type": "function", "function": {"name": "..."}}.
nimbus_toolsآرایهابزارهایی که در سمت اهوس‌ای‌آی اجرا می‌شوند: web_search و fetch_url. بخش جستجوی وب را ببینید.
web_search_optionsشیءجستجوی وب را مانند API شرکت OpenAI فعال می‌کند. محتوای آن استفاده نمی‌شود.

سایر فیلدهای قالب OpenAI پذیرفته و نادیده گرفته می‌شوند. صدا و فایل‌هایی جز تصویر پشتیبانی نمی‌شوند.

پاسخ

{
  "id": "chatcmpl-...",
  "object": "chat.completion",
  "model": "nimbus-2-apex",
  "choices": [{
    "index": 0,
    "finish_reason": "stop",
    "message": {
      "role": "assistant",
      "content": "متن پاسخ.",
      "reasoning_content": "استدلالی که پیش از پاسخ انجام شد."
    }
  }],
  "usage": {"prompt_tokens": 120, "completion_tokens": 310, "total_tokens": 430},
  "nimbus": {"thinking_level": 5, "temperature": 5, "think_words": 160, "forced_close": false, "tokens_per_second": 28.4}
}
  • reasoning_content استدلال مدل و content پاسخ نهایی است.
  • مقدار finish_reason یکی از stop، length (رسیدن پاسخ به max_tokens یا به سقف حافظهٔ متن) یا tool_calls است.
  • nimbus.forced_close زمانی true است که استدلال به سقف سطح خود رسیده و بسته شده باشد.

پخش زنده

با "stream": true پاسخ به‌صورت دنباله‌ای از رویدادهای server-sent ارسال می‌شود که هر کدام یک سطر data: {...} است:

  • choices[0].delta.reasoning_content: بخش بعدی استدلال.
  • choices[0].delta.content: بخش بعدی پاسخ.
  • choices[0].delta.tool_calls: یک فراخوانی ابزار که کامل در یک رویداد ارسال می‌شود.
  • آخرین رویداد شامل finish_reason، usage و nimbus است و پس از آن جریان با data: [DONE] پایان می‌یابد.

خطایی که در میانهٔ پخش رخ دهد به این صورت ارسال می‌شود: data: {"error": {"message": "...", "type": "..."}}.

ابزارها

ابزارها از قالب فراخوانی تابع OpenAI پیروی می‌کنند. هرگاه مدل تصمیم به استفاده از ابزار بگیرد، پاسخ با finish_reason: "tool_calls" و یک فراخوانی در message.tool_calls پایان می‌یابد. تابع را اجرا کنید، پیام دستیار و یک پیام tool حاوی نتیجه را به گفتگو بیفزایید و درخواست را دوباره ارسال کنید:

{"role": "tool", "tool_call_id": "call_...", "content": "نتیجهٔ تابع"}

آرگومان‌های هر فراخوانی با طرح‌وارهٔ پارامترهای همان ابزار مطابقت دارند. در هر پاسخ حداکثر یک فراخوانی بازگردانده می‌شود.

تصویر

پیام کاربر می‌تواند تصویرهایی را به‌صورت بخش‌های image_url قالب OpenAI داشته باشد، به‌شکل نشانی data: (PNG، JPEG، WebP یا GIF) یا یک نشانی https:

{"role": "user", "content": [
  {"type": "text", "text": "این نمودار چه چیزی را نشان می‌دهد؟"},
  {"type": "image_url", "image_url": {"url": "data:image/png;base64,..."}}
]}

مدل فقط متن می‌خواند. هر تصویر ابتدا با ماژول تصویر اهوس‌ای‌آی، apex-imagexo-v1، خوانده می‌شود که متن آن (با OCR، به فارسی و انگلیسی) و شکل‌هایش (مکان، اندازه و رنگ) را به یک صحنهٔ XML تبدیل می‌کند و مدل از روی همین صحنه پاسخ می‌دهد. این ماژول اسناد، تصویر صفحه، جدول، فرم، نمودار و دیاگرام را به‌خوبی می‌خواند، اما محتوای عکس‌ها، مانند چهره یا اشیا، را نمی‌بیند.

  • حداکثر ۴ تصویر در هر درخواست، هر کدام حداکثر ۸ مگابایت.
  • صحنه‌های تصویرهای آخرین پیام در nimbus.images بازگردانده می‌شوند. در نوبت‌های بعدی، به‌جای خود تصویر همین صحنه‌ها را به‌صورت متن بفرستید تا تصویر دوباره خوانده نشود.

عامل‌ها و ابزارها

وقتی درخواستی tools خود شما را همراه دارد، مدل به‌صورت عامل (agent) کار می‌کند: در هر مرحله یا یکی از ابزارهای شما را فراخوانی می‌کند یا پاسخ می‌دهد، و آرگومان‌های فراخوانی از طرح‌وارهٔ پارامترهای همان ابزار پیروی می‌کنند. برای کمک به انتخاب درست، ابزارهایی که نام‌های رایج نوشتن، ویرایش و خواندن فایل، فهرست کردن فایل‌ها و اجرای دستور دارند (مانند Write، Edit، Read، Glob و Bash) به مدل معرفی می‌شوند، و پوشهٔ پروژه‌ای که در پیام system نام برده شده باشد (مانند Primary working directory: ...) به‌عنوان محل فایل‌ها به مدل گفته می‌شود. فهرست ابزارها را به آنچه کار لازم دارد محدود کنید: فهرست طولانی حافظهٔ متن را مصرف می‌کند و انتخاب درست را دشوارتر می‌کند.

با "nimbus_tools": ["web_search", "fetch_url"] (یا web_search_options) مدل می‌تواند پیش از پاسخ در وب جستجو کند و صفحه‌ها را بخواند. این ابزارها روی سرورهای اهوس‌ای‌آی اجرا می‌شوند؛ فراخوانی‌های آن‌ها به شما بازگردانده نمی‌شود و پاسخ با نتایج آن‌ها ادامه می‌یابد. هر پاسخ می‌تواند تا شش مرحله از این نوع داشته باشد.

  • در حالت پخش زنده، هر مرحله در فیلد nimbus_tool گزارش می‌شود: {"id", "name", "arguments", "status"}، که status یکی از running، done یا error است. جستجوی تمام‌شده فهرست results (عنوان، نشانی و خلاصه) را نیز دارد.
  • در پاسخ غیرزنده، مراحل انجام‌شده در nimbus.tools فهرست می‌شوند.

عبارت‌های جستجو به موتورهای جستجوی عمومی ارسال می‌شوند و صفحه‌ها از سایت‌های خودشان دریافت می‌شوند.

خطاها

خطاها در قالب OpenAI بازگردانده می‌شوند: {"error": {"message": "...", "type": "..."}}.

کد وضعیتنوعمعنا
400invalid_request_errorبدنه JSON معتبر نیست، پیامی ندارد، یا آخرین پیام آن از نوع user یا tool نیست.
401authentication_errorکلید ارسال نشده، ناشناخته یا باطل‌شده است.
404invalid_request_errorمسیر یا مدل ناشناخته است.
405invalid_request_errorروش درخواست مجاز نیست.
413invalid_request_errorحجم بدنه بیش از ۱۶ مگابایت است.
429rate_limit_errorسقف مصرف کلید در این دوره تمام شده است. خطا شامل used، limit و period است.
502، 503engine_error، engine_unavailableمدل نتوانست پاسخ دهد. بعداً دوباره تلاش کنید.

حافظهٔ متن و زمان پاسخ

  • هر درخواست در مجموع می‌تواند تا ۴۰٬۹۶۰ توکن استفاده کند: گفتگو، تعریف ابزارها، استدلال و پاسخ. اگر طولانی‌تر باشد، ابتدا توضیحات ابزارها کوتاه می‌شوند و سپس قدیمی‌ترین نوبت‌ها کنار گذاشته می‌شوند؛ اگر آخرین نوبت به‌تنهایی جا نشود، درخواست با خطا پایان می‌یابد.
  • مدل هنگام نیاز راه‌اندازی می‌شود. پس از مدتی بدون درخواست، نخستین پاسخ ممکن است تا دو دقیقه طول بکشد.
  • درخواست‌ها یکی‌یکی پاسخ داده می‌شوند و بقیه در نوبت می‌مانند.
  • درخواست طولانی ممکن است تا یک دقیقه پیش از نخستین توکن زمان ببرد. در این مدت، در پاسخ زنده هر چند ثانیه یک سطر توضیحی (: keepalive) ارسال می‌شود که کلاینت‌های SSE آن را نادیده می‌گیرند.