API Reference
NIM LLM and VLM exposes an OpenAI-compatible inference API and NIM-specific management endpoints. The container’s inference engine, vLLM or SGLang, determines the available inference features. Backend-specific endpoints are labeled below.
Inference Endpoints
The inference engine in the container image, vLLM or SGLang, serves these endpoints. Entries labeled vLLM backend only require a vLLM image.
Render endpoints return the formatted prompt without running inference:
For the full request and response schemas and parameter lists, open the
interactive OpenAPI explorer at /docs on the running container.
For engine documentation, refer to the vLLM OpenAI-Compatible Server documentation or the SGLang documentation.
For Anthropic-compatible request syntax, refer to the Anthropic Messages API documentation.
Management Endpoints
These endpoints are specific to the NIM container and are served by the NIM middleware layer or the nginx proxy.
Examples
The examples below use ${MODEL_NAME} as a shell variable. To find
the model ID for your deployment, query the models endpoint:
Then export it for use in subsequent commands:
The model ID matches the value of NIM_SERVED_MODEL_NAME when the
variable is set explicitly. If the variable is not set, NIM derives the
name automatically. For more information, refer to
Environment Variables.
Chat Completions
To query the Chat Completions API using a text prompt, run the following command:
To stream the response back to the client, run the following command:
To query the Chat Completions API using a text prompt and an input image, run the following command:
Completions
To query the Completions API, run the following command:
Responses (OpenAI Responses API)
To query a model using the OpenAI Responses API, run the following command:
For Codex CLI setup, required engine arguments, and model naming, refer to Use Codex CLI with NIM.
Messages (Anthropic-compatible)
NIM exposes the backend’s Anthropic-compatible API at /v1/messages. NIM routes
these requests through the nginx proxy and does not rewrite the request or
response body.
To send an Anthropic-compatible message request, run the following command:
To stream the response back to the client, run the following command:
Streaming responses use Server-Sent Events (SSE) with Anthropic event types
such as message_start, content_block_start, content_block_delta,
content_block_stop, message_delta, and message_stop.
The Anthropic format uses a top-level system field instead of a system
message:
To count tokens in a request without running inference, run the following command:
NIM does not validate the x-api-key header. When you use Anthropic SDK
clients, set the API key to any non-empty string that satisfies the client.
The /v1/messages endpoint implements the core Anthropic Messages API format.
Some Anthropic-specific features depend on the model and inference backend.
- Tool use (
tool_useandtool_resultcontent blocks) requires a model with tool-calling support. - Extended thinking (
thinkingcontent blocks) requires support from both the model and the inference backend. - The
anthropic-versionheader is accepted but not enforced. - Batch and admin endpoints are not supported.
For Claude Code setup and model selection, refer to Use Claude Code with NIM.
Anthropic Python SDK
To use the Anthropic Python SDK with NIM, point the client at the NIM endpoint and set the API key to any non-empty string:
To stream the response:
To count tokens without running inference:
Tokenize and Detokenize
To tokenize input text into token IDs, run the following command:
Token IDs are model-specific: the same text tokenizes to different IDs across
tokenizers. To make the detokenize example round-trip correctly against the
model you are running, obtain the token IDs from /tokenize first, then pass
them to /detokenize:
List Models
To list the available models, run the following command:
Health Checks
To perform a liveness or readiness health check, run the following commands:
Metadata and Version
To query the deployment metadata and version, run the following commands:
Disaggregated Generation (vLLM Backend Only)
Use a vLLM image to access this endpoint.
The /inference/v1/generate endpoint accepts and returns raw token IDs and
bypasses chat template rendering. Use it for disaggregated prefill/decode
deployments and other advanced use cases that require direct control over tokens.
On vLLM 0.30.0 and later, start the server with --enable-scale-out to register
this endpoint. Without the flag, requests return HTTP 404 and the endpoint does
not appear in /openapi.json. Add the flag to NIM_PASSTHROUGH_ARGS. If the
image already sets the variable, keep its existing flags and append
--enable-scale-out so that your configuration preserves the image’s flags.
To generate from a sequence of input tokens, tokenize the prompt and then post
the token IDs to /inference/v1/generate.
The response contains the generated token IDs in choices[].token_ids. Set
sampling_params.detokenize to true to have the engine convert the output
tokens to text before returning them. For the full request and response schemas,
refer to the interactive OpenAPI explorer at /docs.
Generative Scoring (vLLM Backend Only)
Use a vLLM image to access this endpoint.
The /generative_scoring endpoint returns log probability scores for a
fixed set of candidate label tokens. Use it as an alternative to the vLLM
pooling endpoints (/score, /rerank, /classify, and /pooling).
The request requires the following fields:
query: the query text (or pre-tokenized token IDs).items: a list of item texts (or pre-tokenized token IDs) to score against the query.label_token_ids: the token IDs to compute probabilities for. These IDs are model-specific — obtain them from/tokenizefor the labels you want to score against, such as"yes"and"no".
Because label_token_ids must match the runtime tokenizer, derive them
dynamically rather than hardcoding integers:
The response returns one score per item in data[].score, corresponding to
the probability of the first label token following the query + item prompt.
For the full request and response schema for your container, refer to the
interactive OpenAPI explorer at /docs. For an end-to-end example using vLLM,
refer to tests/entrypoints/openai/generative_scoring/test_generative_scoring_e2e.py
in the vllm-project/vllm GitHub repository.