### JSON Request Example for Qwen3.5-397B-A17B API Source: https://docs.api.nvidia.com/nim/reference/qwen-qwen3-5-397b-a17b/-infer This JSON object represents a sample request payload for the Qwen3.5-397B-A17B model via the NVIDIA NIM API. It includes parameters for the model, messages (with text and video URL content), generation settings like max_tokens, temperature, and streaming options. ```json { "model": "qwen/qwen3.5-397b-a17b", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe what you see in this video." }, { "type": "video_url", "video_url": { "url": "https://assets.ngc.nvidia.com/products/api-catalog/nvidia-nemotron-nano-12b-v2-vl/nvidia-studio-itns-wk53-scene-in-omniverse-1280w.mp4" } } ] } ], "max_tokens": 1024, "temperature": 0.6, "top_p": 0.95, "top_k": 20, "presence_penalty": 0.0, "repetition_penalty": 1.0, "stream": true, "chat_template_kwargs": { "enable_thinking": true } } ``` -------------------------------- ### JSON Response Example from Qwen3.5-397B-A17B API Source: https://docs.api.nvidia.com/nim/reference/qwen-qwen3-5-397b-a17b/-infer This JSON object illustrates a typical response from the Qwen3.5-397B-A17B model via the NVIDIA NIM API. It contains metadata such as the response ID, creation timestamp, model used, and usage statistics (tokens). The core content is within the 'choices' array, detailing the assistant's message. ```json { "id": "chatcmpl-ghi789", "object": "chat.completion", "created": 1677858400, "model": "qwen/qwen3.5-397b-a17b", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "The video shows a snowy 3D environment with a small cabin and nearby objects." }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 640, "completion_tokens": 42, "total_tokens": 682 } } ``` -------------------------------- ### Python API Request for Qwen-Qwen3-5-397B Source: https://docs.api.nvidia.com/nim/reference/qwen-qwen3-5-397b-a17b/-infer This snippet demonstrates how to make a POST request to the NVIDIA NIM API to invoke the Qwen-Qwen3-5-397B model. It handles both streaming and non-streaming responses and includes optional parameters for tools and tool choice. Ensure you have the `requests` library installed and the `invoke_url` and `headers` correctly configured. ```python import requests import json # Assume invoke_url and headers are defined elsewhere # For example: # invoke_url = "YOUR_NIM_INVOKE_URL" # headers = {"Authorization": "Bearer YOUR_API_KEY"} payload = {} # Example payload construction (adapt as needed based on request.messages, request.tools, etc.) # payload["messages"] = request.messages # if request.tools: # payload["tools"] = request.tools # if request.tool_choice: # payload["tool_choice"] = request.tool_choice # stream = True # or False # response = requests.post(invoke_url, headers=headers, json=payload, stream=stream) # if stream: # for line in response.iter_lines(): # if line: # print(line.decode("utf-8")) # else: # print(response.json()) ``` -------------------------------- ### GET /websites/api_nvidia_nim_reference_qwen-qwen3-5-397b-a17b Source: https://docs.api.nvidia.com/nim/reference/qwen-qwen3-5-397b-a17b/-statuspolling Retrieves the result of a previously initiated function invocation that returned a 202 Accepted status. ```APIDOC ## GET /websites/api_nvidia_nim_reference_qwen-qwen3-5-397b-a17b ### Description Gets the result of an earlier function invocation request that returned a status of 202. ### Method GET ### Endpoint /websites/api_nvidia_nim_reference_qwen-qwen3-5-397b-a17b ### Parameters #### Query Parameters - **invocationId** (string) - Required - The unique identifier for the function invocation whose result is being requested. ### Response #### Success Response (200) - **status** (string) - The final status of the invocation (e.g., 'completed', 'failed'). - **result** (object) - The output of the function invocation if successful. - **error** (object) - Details about the error if the invocation failed. #### Response Example ```json { "status": "completed", "result": { "output": "This is the result of the function call." } } ``` ``` -------------------------------- ### LangChain Integration for Qwen-Qwen3-5-397B Source: https://docs.api.nvidia.com/nim/reference/qwen-qwen3-5-397b-a17b/-infer This code demonstrates how to use the Qwen-Qwen3-5-397B model within a LangChain application. It supports text-based and image-based inputs. For image inputs, it requires images to be saved as `image_1.png`, `image_2.png`, etc., in the same directory. Video input is not supported via LangChain for this model. The snippet handles both streaming and non-streaming invocations. ```python from langchain_nvidia_ai_endpoints import ChatNVIDIA from langchain_core.messages import HumanMessage import base64 # Assume request.model, request.temperature, request.top_p, request.max_tokens are defined # and request.messages contains the conversation history or initial prompt. # Also assume $NVIDIA_API_KEY environment variable is set. client = ChatNVIDIA( model=request.model, api_key="$NVIDIA_API_KEY", temperature=request.temperature, top_p=request.top_p, max_completion_tokens=request.max_tokens, ) # Placeholder for image handling logic if needed # def read_b64(path): # with open(path, "rb") as f: # return base64.b64encode(f.read()).decode() # Placeholder for message construction # lc_messages = [ # HumanMessage( # content=[ # {"type": "text", "text": "Describe this image."}, # # {"type": "image_url", "image_url": {"url": f"data:image/png;base64,{image_b64}"}} # ] # ) # ] # Placeholder for streaming or non-streaming invocation # if request.stream: # for chunk in client.stream(lc_messages): # # Process chunk # print(chunk.content, end="") # else: # response = client.invoke(lc_messages) # print(response.content) ``` -------------------------------- ### Get Function Invocation Result - OpenAPI Source: https://docs.api.nvidia.com/nim/reference/qwen-qwen3-5-397b-a17b/-statuspolling This snippet defines the GET endpoint for retrieving the status of a function invocation request. It specifies the path parameter 'requestId', expected responses (200, 202, 422, 500), and relevant headers for polling. ```json { "tags": [ "Multimodal API" ], "summary": "Gets the result of an earlier function invocation request that returned a status of 202.", "operationId": "getFunctionInvocationResult", "parameters": [ { "name": "requestId", "in": "path", "description": "requestId to poll results", "required": true, "schema": { "type": "string", "format": "uuid", "maxLength": 36 } } ], "responses": { "200": { "description": "Invocation is fulfilled", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ChatCompletionResponse" } } } }, "202": { "description": "Result is pending. Client should poll using the requestId.\n", "content": { "application/json": { "example": {}, "schema": {} } }, "headers": { "NVCF-REQID": { "description": "requestId required for pooling", "schema": { "type": "string", "format": "uuid", "maxLength": 36 } }, "NVCF-STATUS": { "description": "Invocation status", "schema": { "type": "string", "format": "^[a-zA-Z-]{1,64}$", "maxLength": 64 } } } }, "422": { "description": "The invocation ended with an error.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }, "500": { "description": "The invocation ended with an error.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } } } } ``` -------------------------------- ### GET /status/{requestId} Source: https://docs.api.nvidia.com/nim/reference/qwen-qwen3-5-397b-a17b/-statuspolling Retrieves the result of a previously submitted function invocation request. This endpoint is used to poll for the status of asynchronous operations, particularly when the initial request returned a 202 Accepted status. ```APIDOC ## GET /status/{requestId} ### Description Gets the result of an earlier function invocation request that returned a status of 202. ### Method GET ### Endpoint /status/{requestId} ### Parameters #### Path Parameters - **requestId** (string) - Required - requestId to poll results ### Request Example (No request body for GET requests) ### Response #### Success Response (200) - **id** (string) - The unique identifier for the completion. - **object** (string) - The type of object returned, always "chat.completion". - **created** (integer) - The Unix timestamp (in seconds) of when the completion was created. - **model** (string) - The model used for the completion. - **choices** (array) - A list of completion choices. - **usage** (object) - Information about the token usage. #### Pending Response (202) - **NVCF-REQID** (string) - The request ID required for polling. - **NVCF-STATUS** (string) - The current status of the invocation. #### Error Response (422, 500) - **code** (string) - An error code. - **message** (string) - A detailed error message. #### Response Example (200) ```json { "id": "chatcmpl-123", "object": "chat.completion", "created": 1677652288, "model": "qwen/qwen3.5-397b-a17b", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "Hello world!" }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 10, "completion_tokens": 20, "total_tokens": 30 } } ``` #### Response Example (202) (No specific JSON body, headers are important) #### Response Example (422/500) ```json { "code": "invalid_request", "message": "The request was invalid." } ``` ``` -------------------------------- ### Send Multimodal Request to Qwen3.5-397B-A17B API (Python) Source: https://docs.api.nvidia.com/nim/reference/qwen-qwen3-5-397b-a17b/-infer This Python script demonstrates how to send a multimodal request to the Qwen3.5-397B-A17B model via the NVIDIA NIM API. It supports text, image, and video inputs, with options for streaming responses. The script includes logic for encoding media files into base64 and constructing the appropriate JSON payload. ```python import requests import base64 def read_b64(path): with open(path, "rb") as f: return base64.b64encode(f.read()).decode() invoke_url = "https://integrate.api.nvidia.com/v1/chat/completions" stream = True # Assuming image_b64s and video_b64s are populated from local files # Example: image_b64s = [read_b64("image_1.png")] # Example: video_b64s = [read_b64("video_1.mp4")] # Placeholder for actual media data if not using the template's file reading image_b64s = [] video_b64s = [] # Constructing messages based on content type # This part would be dynamically generated based on the input content # For demonstration, using a simplified structure similar to the example messages = [ { "role": "user", "content": [ { "type": "text", "text": "Describe what you see in this video." }, { "type": "video_url", "video_url": { "url": "https://assets.ngc.nvidia.com/products/api-catalog/nvidia-nemotron-nano-12b-v2-vl/nvidia-studio-itns-wk53-scene-in-omniverse-1280w.mp4" } } ] } ] # If using the template's logic for media embedding: # rendered_messages = [ # { # "role": "user", # "content": [ # { "type": "text", "text": "Describe what you see in this video." }, # { "type": "video_url", "video_url": { "url": f"data:video/mp4;base64,{video_b64s[0]}" } } # Example if video was base64 encoded # ] # } # ] headers = { "Authorization": "Bearer $NVIDIA_API_KEY", "Accept": "text/event-stream" if stream else "application/json" } payload = { "model": "qwen/qwen3.5-397b-a17b", "messages": messages, # Use rendered_messages if dynamically processing media "max_tokens": 1024, "temperature": 0.6, "top_p": 0.95, "top_k": 20, "presence_penalty": 0.0, "repetition_penalty": 1.0, "stream": stream, "chat_template_kwargs": { "enable_thinking": True } } response = requests.post(invoke_url, headers=headers, json=payload, stream=stream) if stream: for line in response.iter_lines(): if line: print(line.decode('utf-8')) else: print(response.json()) ``` -------------------------------- ### POST /v2/nvcf/pexec/functions/create Source: https://docs.api.nvidia.com/nim/reference/qwen-qwen3-5-397b-a17b/-infer Creates a chat completion using the Qwen3.5-397B-A17B model. Supports text and image inputs, and can stream responses. ```APIDOC ## POST /v2/nvcf/pexec/functions/create ### Description Creates a chat completion using the Qwen3.5-397B-A17B model. This endpoint can handle text and image inputs, and offers the option to stream the response for real-time updates. ### Method POST ### Endpoint /v2/nvcf/pexec/functions/create ### Parameters #### Query Parameters - **stream** (boolean) - Optional - If set to `true`, the response will be streamed. #### Request Body - **model** (string) - Required - The model to use for the chat completion (e.g., "qwen/qwen3.5-397b-a17b"). - **messages** (array) - Required - An array of message objects representing the conversation history. - **role** (string) - Required - The role of the author of the message ('user' or 'assistant'). - **content** (string or array) - Required - The content of the message. Can be a string for text-only messages or an array for multi-modal messages. - **type** (string) - Required - The type of content ('text' or 'image_url'). - **text** (string) - Required if type is 'text' - The text content. - **image_url** (object) - Required if type is 'image_url' - An object containing the URL of the image. - **url** (string) - Required - The URL of the image. - **max_tokens** (integer) - Optional - The maximum number of tokens to generate in the completion. - **temperature** (number) - Optional - Controls randomness. Lower values make the output more deterministic. - **top_p** (number) - Optional - Controls diversity via nucleus sampling. - **top_k** (integer) - Optional - Controls diversity via top-k sampling. - **presence_penalty** (number) - Optional - Penalizes new tokens based on whether they appear in the text so far. - **repetition_penalty** (number) - Optional - Penalizes new tokens based on their existing frequency in the text so far. - **chat_template_kwargs** (object) - Optional - Additional keyword arguments for chat templating. - **enable_thinking** (boolean) - Optional - Enables thinking process output. ### Request Example ```json { "model": "qwen/qwen3.5-397b-a17b", "messages": [ { "role": "user", "content": "Which number is larger, 9.11 or 9.8?" } ], "max_tokens": 1024, "temperature": 0.6, "top_p": 0.95, "top_k": 20, "presence_penalty": 0.0, "repetition_penalty": 1.0, "stream": false, "chat_template_kwargs": { "enable_thinking": true } } ``` ### Response #### Success Response (200) - **id** (string) - Unique identifier for the chat completion. - **object** (string) - Type of object, e.g., "chat.completion". - **created** (integer) - Unix timestamp of creation. - **model** (string) - The model used for the completion. - **choices** (array) - An array of completion choices. - **index** (integer) - Index of the choice. - **message** (object) - The message content. - **role** (string) - Role of the message author ('assistant'). - **content** (string) - The generated text content. - **finish_reason** (string) - The reason the model stopped generating tokens (e.g., "stop"). - **usage** (object) - Token usage statistics. - **prompt_tokens** (integer) - Number of tokens in the prompt. - **completion_tokens** (integer) - Number of tokens in the completion. - **total_tokens** (integer) - Total tokens used. #### Response Example ```json { "id": "chatcmpl-abc123", "object": "chat.completion", "created": 1677858242, "model": "qwen/qwen3.5-397b-a17b", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "9.8 is larger than 9.11." }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 256, "completion_tokens": 24, "total_tokens": 280 } } ``` #### Error Response (500) - **type** (string) - Error type identifier. - **title** (string) - A short, human-readable summary of the error. - **status** (integer) - The HTTP status code. - **detail** (string) - A human-readable explanation specific to this occurrence of the problem. - **instance** (string) - URI that identifies this specific occurrence of the problem. - **requestId** (string) - Unique identifier for the request. #### Error Response Example ```json { "type": "urn:nvcf-worker-service:problem-details:internal-server-error", "title": "Internal Server Error", "status": 500, "detail": "An unexpected error occurred.", "instance": "/v2/nvcf/pexec/functions/e598bfc1-b058-41af-869d-556d3c7e1b48", "requestId": "3fa85f64-5717-4562-b3fc-2c963f66afa6" } ``` ``` -------------------------------- ### Text Generation with Qwen3.5-397B-A17B Source: https://docs.api.nvidia.com/nim/reference/qwen-qwen3-5-397b-a17b/-infer This endpoint facilitates text generation using the Qwen3.5-397B-A17B model. You can customize generation parameters such as temperature, top_p, and max_tokens. ```APIDOC ## POST /websites/api_nvidia_nim_reference_qwen-qwen3-5-397b-a17b ### Description Generates text based on the provided prompt and configuration using the Qwen3.5-397B-A17B model. ### Method POST ### Endpoint /websites/api_nvidia_nim_reference_qwen-qwen3-5-397b-a17b ### Parameters #### Request Body - **messages** (array) - Required - An array of message objects, each with a 'role' and 'content'. - **model** (string) - Optional - The model to use. Defaults to "qwen/qwen3.5-397b-a17b". - **chat_template_kwargs** (object | null) - Optional - Optional kwargs forwarded to the model chat template. Use {"enable_thinking": true} to enable thinking mode or {"enable_thinking": false} to disable it. - **tools** (array | null) - Optional - Optional OpenAI-compatible tool definitions for function calling. - **max_tokens** (integer | null) - Optional - The maximum number of tokens that can be generated. Defaults to 16384. - **seed** (integer | null) - Optional - Changing the seed will produce a different response with similar characteristics. Fixing the seed will reproduce the same results if all other parameters are also kept constant. - **stream** (boolean | null) - Optional - If set, partial message deltas will be sent, like in ChatGPT. Defaults to false. - **temperature** (number | null) - Optional - What sampling temperature to use, between 0 and 1. Recommended values are 0.6 in thinking mode and 0.7 in non-thinking mode. Defaults to 0.6. - **top_p** (number | null) - Optional - Nucleus sampling threshold. Recommended values are 0.95 in thinking mode and 0.8 in non-thinking mode. Defaults to 0.95. - **top_k** (integer | null) - Optional - Limits sampling to the top_k most likely tokens. Recommended value is 20 for both thinking and non-thinking modes. Defaults to 20. - **presence_penalty** (number | null) - Optional - Penalizes tokens already present in the generated text. Recommended values are 0.0 in thinking mode and 1.5 in non-thinking mode. Defaults to 0. - **repetition_penalty** (number | null) - Optional - Penalty applied to repeated tokens. Recommended value is 1.0 for both thinking and non-thinking modes. Defaults to 1. ### Request Example ```json { "messages": [ { "role": "user", "content": "Hello, who are you?" } ], "model": "qwen/qwen3.5-397b-a17b", "temperature": 0.7, "max_tokens": 100 } ``` ### Response #### Success Response (200) - **choices** (array) - An array of message objects representing the model's response. - **created** (integer) - The timestamp of when the response was created. - **id** (string) - A unique identifier for the response. - **model** (string) - The model used for generation. - **object** (string) - The type of object returned (e.g., 'chat.completion'). - **usage** (object) - Information about token usage. #### Response Example ```json { "choices": [ { "finish_reason": "stop", "index": 0, "message": { "content": "I am a large language model, trained by NVIDIA.", "role": "assistant" } } ], "created": 1700000000, "id": "chatcmpl-xxxxxxxxxxxxxxxxx", "model": "qwen/qwen3.5-397b-a17b", "object": "chat.completion", "usage": { "completion_tokens": 10, "prompt_tokens": 20, "total_tokens": 30 } } ``` ``` -------------------------------- ### Invoke NVIDIA Nim Qwen3-5-397b API with Node.js Source: https://docs.api.nvidia.com/nim/reference/qwen-qwen3-5-397b-a17b/-infer This Node.js snippet demonstrates how to invoke the NVIDIA Nim Qwen3-5-397b API for chat completions. It handles both text and media (image/video) inputs, constructs the appropriate payload, and sends a POST request using Axios. The code supports streaming responses and includes various parameters for controlling the generation process. ```javascript import axios from 'axios'; import { readFile } from 'node:fs/promises'; const invokeUrl = "https://integrate.api.nvidia.com/v1/chat/completions"; const stream = <%- request.stream %>; <% const messages = JSON.stringify(request.messages) const firstContent = typeof request.messages?.[0]?.content === "string" ? request.messages[0].content : ""; const hasImage = /]*\/?>/i.test(firstContent); const hasVideo = /]*\/?>/i.test(firstContent); const hasMedia = hasImage || hasVideo; const imageCount = (firstContent.match(/]*\/?>/gi) || []).length; const videoCount = (firstContent.match(/]*\/?>/gi) || []).length; let rendered_messages; if (hasMedia) { const tagRegex = /<(img|video)\b[^>]*\/?>/gi; const contentParts = []; let imgIdx = 0; let vidIdx = 0; let lastIdx = 0; let tagMatch; while ((tagMatch = tagRegex.exec(firstContent)) !== null) { const leadingText = firstContent.slice(lastIdx, tagMatch.index); if (leadingText.trim()) { contentParts.push({ type: "text", text: leadingText }); } if ((tagMatch[1] || "").toLowerCase() === "img") { contentParts.push({ type: "image_url", image_url: { url: `__IMAGE_${imgIdx}__` } }); imgIdx += 1; } else { contentParts.push({ type: "video_url", video_url: { url: `__VIDEO_${vidIdx}__` } }); vidIdx += 1; } lastIdx = tagRegex.lastIndex; } const trailingText = firstContent.slice(lastIdx); if (trailingText.trim()) { contentParts.push({ type: "text", text: trailingText }); } let renderedContent = JSON.stringify(contentParts, null, 8); for (let i = 0; i < imgIdx; i++) { renderedContent = renderedContent.replace( `"__IMAGE_${i}__"`, `\`data:image/png;base64,\${image_${i + 1}_b64}\``, ); } for (let i = 0; i < vidIdx; i++) { renderedContent = renderedContent.replace( `"__VIDEO_${i}__"`, `\`data:video/mp4;base64,\${video_${i + 1}_b64}\``, ); } rendered_messages = `[ { "role": "user", "content": ${renderedContent} } ]`; } else { rendered_messages = messages } %> const headers = { "Authorization": "Bearer $NVIDIA_API_KEY", "Accept": stream ? "text/event-stream" : "application/json" }; <% if (hasMedia) { %> Promise.all([<% for (let i = 1; i <= imageCount; i++) { %>readFile("image_<%- i %>.png"), <% } %><% for (let i = 1; i <= videoCount; i++) { %>readFile("video_<%- i %>.mp4"), <% } %>]) .then((imageBuffers) => { <% for (let i = 1; i <= imageCount; i++) { %>const image_<%- i %>_b64 = Buffer.from(imageBuffers[<%- i - 1 %>]).toString('base64'); <% } %> <% for (let i = 1; i <= videoCount; i++) { %>const video_<%- i %>_b64 = Buffer.from(imageBuffers[<%- imageCount + i - 1 %>]).toString('base64'); <% } %> const payload = { "model": `<%- request.model %>`, "messages": <%- rendered_messages %>, "max_tokens": <%- request.max_tokens %>, "temperature": <%- request.temperature.toFixed(2) %>, "top_p": <%- request.top_p.toFixed(2) %>, <%- request.top_k != null ? '"top_k": ' + request.top_k + ',' : '' %> <%- request.presence_penalty != null ? '"presence_penalty": ' + request.presence_penalty + ',' : '' %> <%- request.repetition_penalty != null ? '"repetition_penalty": ' + request.repetition_penalty + ',' : '' %> "stream": stream, <%- request.chat_template_kwargs ? '"chat_template_kwargs": ' + JSON.stringify(request.chat_template_kwargs) + ',' : '' %> <% if (request.tools) { %>"tools": <%- JSON.stringify(request.tools) %>,<% } %> <% if (request.tool_choice) { %>"tool_choice": <%- JSON.stringify(request.tool_choice) %><% } %> }; return axios.post(invokeUrl, payload, { headers: headers, responseType: stream ? 'stream' : 'json' }); }) <% } else { %> const payload = { "model": "<%- request.model %>", "messages": <%- rendered_messages %>, "max_tokens": <%- request.max_tokens %>, "temperature": <%- request.temperature.toFixed(2) %>, "top_p": <%- request.top_p.toFixed(2) %>, <%- request.top_k != null ? '"top_k": ' + request.top_k + ',' : '' %> <%- request.presence_penalty != null ? '"presence_penalty": ' + request.presence_penalty + ',' : '' %> <%- request.repetition_penalty != null ? '"repetition_penalty": ' + request.repetition_penalty + ',' : '' %> "stream": stream, <%- request.chat_template_kwargs ? '"chat_template_kwargs": ' + JSON.stringify(request.chat_template_kwargs) + ',' : '' %> <% if (request.tools) { %>"tools": <%- JSON.stringify(request.tools) %>,<% } %> <% if (request.tool_choice) { %>"tool_choice": <%- JSON.stringify(request.tool_choice) %><% } %> }; return axios.post(invokeUrl, payload, { headers: headers, responseType: stream ? 'stream' : 'json' }); <% } %> ``` -------------------------------- ### Chat Completion API Source: https://docs.api.nvidia.com/nim/reference/qwen-qwen3-5-397b-a17b/-infer This endpoint allows you to generate text completions for a given prompt using the Qwen3.5-397B-a17b model. It supports streaming responses for real-time output. ```APIDOC ## POST /websites/api_nvidia_nim_reference_qwen-qwen3-5-397b-a17b ### Description Generates text completions for a given prompt using the Qwen3.5-397B-a17b model. Supports streaming responses. ### Method POST ### Endpoint /websites/api_nvidia_nim_reference_qwen-qwen3-5-397b-a17b ### Parameters #### Query Parameters - **stream** (boolean) - Optional - If set to true, streams response as chunks. #### Request Body - **model** (string) - Required - The model to use for completion (e.g., "qwen/qwen3.5-397b-a17b"). - **messages** (array) - Required - An array of message objects representing the conversation history. - **role** (string) - Required - The role of the message sender ('user' or 'assistant'). - **content** (string) - Required - The content of the message. - **temperature** (number) - Optional - Controls randomness. Lower values make output more focused and deterministic. - **max_tokens** (integer) - Optional - The maximum number of tokens to generate in the completion. - **stop** (array) - Optional - A sequence where the API will stop generating further tokens. ### Request Example ```json { "model": "qwen/qwen3.5-397b-a17b", "messages": [ {"role": "user", "content": "Hello!"} ], "temperature": 0.7, "max_tokens": 50 } ``` ### Response #### Success Response (200) - **id** (string) - Unique identifier for the completion. - **object** (string) - Type of the object, e.g., "chat.completion". - **created** (integer) - Timestamp of creation. - **model** (string) - The model used for completion. - **choices** (array) - An array of completion choices. - **index** (integer) - Index of the choice. - **message** (object) - The message object. - **role** (string) - The role of the message sender ('assistant'). - **content** (string) - The generated text content. - **finish_reason** (string) - The reason the generation finished (e.g., "stop", "length"). - **usage** (object) - Token usage information. - **prompt_tokens** (integer) - Number of tokens in the prompt. - **completion_tokens** (integer) - Number of tokens in the completion. - **total_tokens** (integer) - Total tokens used. #### Response Example ```json { "id": "chatcmpl-12345", "object": "chat.completion", "created": 1677652288, "model": "qwen/qwen3.5-397b-a17b", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "Hello there! How can I help you today?" }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 9, "completion_tokens": 12, "total_tokens": 21 } } ``` #### Streaming Response Example (Chunk) ```json { "id": "chatcmpl-12345", "object": "chat.completion.chunk", "created": 1677652288, "model": "qwen/qwen3.5-397b-a17b", "choices": [ { "index": 0, "delta": { "role": "assistant" }, "finish_reason": null } ] } ``` ### Security - **Token**: Requires Bearer token authentication. ``` -------------------------------- ### Standardize Video Preprocessor Configuration for Long Video Understanding Source: https://docs.api.nvidia.com/nim/reference/qwen-qwen3-5-397b-a17b/index This JSON configuration optimizes inference efficiency for long video understanding by adjusting the 'longest_edge' parameter. Setting it to 469,762,048 enables higher frame-rate sampling for hour-scale videos, leading to superior performance. The 'shortest_edge' parameter is also included for completeness. ```json { "longest_edge": 469762048, "shortest_edge": 4096 } ``` -------------------------------- ### Create Chat Completion with Image Input (JSON) Source: https://docs.api.nvidia.com/nim/reference/qwen-qwen3-5-397b-a17b/-infer This JSON payload demonstrates how to create a chat completion request that includes an image. It specifies the model, user messages with both text and image URLs, and generation parameters like max_tokens, temperature, and streaming. ```json { "model": "qwen/qwen3.5-397b-a17b", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "What is in this image?" }, { "type": "image_url", "image_url": { "url": "https://assets.ngc.nvidia.com/products/api-catalog/phi-3-5-vision/example1b.jpg" } } ] } ], "max_tokens": 1024, "temperature": 0.6, "top_p": 0.95, "top_k": 20, "presence_penalty": 0.0, "repetition_penalty": 1.0, "stream": true, "chat_template_kwargs": { "enable_thinking": true } } ``` -------------------------------- ### OpenAPI Definition - Main Structure Source: https://docs.api.nvidia.com/nim/reference/qwen-qwen3-5-397b-a17b/-statuspolling This snippet represents the root of the OpenAPI definition file. It includes metadata about the API, server information, tags for grouping operations, and references to the paths and components defined within the specification. ```json { "openapi": "3.1.0", "info": { "title": "NVIDIA NIM API for qwen/qwen3.5-397b-a17b", "description": "The NVIDIA NIM REST API. Please see https://docs.api.nvidia.com/nim/reference/qwen-qwen3-5-397b-a17b for more details.", "version": "1.0.0", "termsOfService": "https://nvidia.com/legal/terms-of-use", "contact": { "name": "NVIDIA Support", "url": "https://help.nvidia.com/" }, "license": { "name": "NVIDIA Open Model License", "url": "https://www.nvidia.com/en-us/agreements/enterprise-software/nvidia-open-model-license/" } }, "servers": [ { "url": "https://integrate.api.nvidia.com/v1" } ], "tags": [ { "name": "Multimodal API", "description": "This API performs inference using visual language understanding models" } ], "paths": {}, "security": [ { "Token": [] } ], "components": { "securitySchemes": { "Token": { "type": "http", "scheme": "bearer" } }, "schemas": {} } } ``` -------------------------------- ### Send Chat Completion Request with JavaScript (Axios) Source: https://docs.api.nvidia.com/nim/reference/qwen-qwen3-5-397b-a17b/-infer This snippet demonstrates how to send a chat completion request to the NVIDIA NIM API using Axios in JavaScript. It handles both streaming and non-streaming responses, including error handling for HTTP requests and response data. Dependencies include the 'axios' library. ```javascript Promise.resolve( axios.post(invokeUrl, payload, { headers: headers, responseType: stream ? 'stream' : 'json' }) ) .then(response => { if (stream) { response.data.on('data', (chunk) => { console.log(chunk.toString()); }); } else { console.log(JSON.stringify(response.data)); } }) .catch(error => { if (error.response) { console.error(`HTTP ${error.response.status}`); if (error.response.data?.on) { error.response.data.on('data', (chunk) => console.error(chunk.toString())); } else { console.error(error.response.data); } } else { console.error(error); } }); ``` -------------------------------- ### Chat Completions API Source: https://docs.api.nvidia.com/nim/reference/qwen-qwen3-5-397b-a17b/-infer This endpoint allows you to send messages to the Qwen-Qwen3-5-397B-A17B model and receive chat completions. It supports streaming responses and can handle text, image, and video content. ```APIDOC ## POST /v1/chat/completions ### Description Sends messages to the chat model and receives a streaming or non-streaming response. ### Method POST ### Endpoint https://integrate.api.nvidia.com/v1/chat/completions ### Parameters #### Query Parameters - **stream** (boolean) - Optional - Whether to stream the response. #### Request Body - **model** (string) - Required - The model to use for completions (e.g., "qwen-qwen3-5-397b-a17b"). - **messages** (array) - Required - An array of message objects representing the conversation history. - **role** (string) - Required - The role of the author (e.g., "user", "assistant"). - **content** (string or array) - Required - The content of the message. Can be a string or an array of content parts (text, image_url, video_url). - **type** (string) - Required - The type of content part (e.g., "text", "image_url", "video_url"). - **text** (string) - Required if type is "text" - The text content. - **image_url** (object) - Required if type is "image_url" - An object containing the image URL. - **url** (string) - Required - The URL of the image. - **video_url** (object) - Required if type is "video_url" - An object containing the video URL. - **url** (string) - Required - The URL of the video. - **max_tokens** (integer) - Required - The maximum number of tokens to generate in the completion. - **temperature** (number) - Required - Controls randomness. Lower values make the output more deterministic. - **top_p** (number) - Required - Controls diversity via nucleus sampling. - **top_k** (integer) - Optional - Filters the model's vocabulary during generation. - **presence_penalty** (number) - Optional - Number penalty to apply to new tokens based on their existing frequency. - **repetition_penalty** (number) - Optional - Number penalty to apply to new tokens based on their presence in the generated text so far. - **chat_template_kwargs** (object) - Optional - Additional arguments for chat templating. - **tools** (array) - Optional - A list of tools the model can use. - **tool_choice** (object) - Optional - Controls which tool the model should use. ### Request Example ```json { "model": "qwen-qwen3-5-397b-a17b", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "What's in this image?" }, { "type": "image_url", "image_url": { "url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA..." } } ] } ], "max_tokens": 512, "temperature": 0.7, "top_p": 0.9 } ``` ### Response #### Success Response (200) - **id** (string) - Unique identifier for the completion. - **object** (string) - Type of object returned (e.g., "chat.completion"). - **created** (integer) - Unix timestamp of when the completion was created. - **model** (string) - The model used for the completion. - **choices** (array) - An array of completion choices. - **index** (integer) - Index of the choice. - **message** (object) - The message content from the model. - **role** (string) - The role of the author (e.g., "assistant"). - **content** (string) - The content of the message. - **finish_reason** (string) - The reason the model stopped generating tokens (e.g., "stop", "length"). - **usage** (object) - Usage statistics for the completion. - **prompt_tokens** (integer) - Number of tokens in the prompt. - **completion_tokens** (integer) - Number of tokens in the completion. - **total_tokens** (integer) - Total tokens used. #### Response Example ```json { "id": "chatcmpl-12345", "object": "chat.completion", "created": 1677652288, "model": "qwen-qwen3-5-397b-a17b", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "This is a sample response from the model." }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 10, "completion_tokens": 20, "total_tokens": 30 } } ``` ``` -------------------------------- ### Create Chat Completion with Text Input (JSON) Source: https://docs.api.nvidia.com/nim/reference/qwen-qwen3-5-397b-a17b/-infer This JSON payload illustrates a standard chat completion request using only text input. It includes the model name, user messages, and parameters to control the output, such as max_tokens and temperature. This is suitable for text-based queries. ```json { "model": "qwen/qwen3.5-397b-a17b", "messages": [ { "role": "user", "content": "Which number is larger, 9.11 or 9.8?" } ], "max_tokens": 1024, "temperature": 0.6, "top_p": 0.95, "top_k": 20, "presence_penalty": 0.0, "repetition_penalty": 1.0, "stream": true, "chat_template_kwargs": { "enable_thinking": true } } ```