### 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 = /