Skip to content

M31A talks to NVIDIA NIM through an OpenAI-compatible HTTP API. The same generator can target any compatible endpoint, including a local vLLM server or a corporate gateway. This tutorial configures one without changing source code.

Prerequisites ​

  • An OpenAI-compatible endpoint exposing /chat/completions (and ideally /models).
  • An API key for that endpoint, if it requires one.
  • M31A installed; see Authentication.

1. Understand provider selection ​

packages/core/src/providers/registry.ts defines the precedence:

  1. an explicit provider ID from --provider or M31A_PROVIDER;
  2. a saved selection from settings;
  3. the built-in nvidia-nim default.

An unknown explicit ID is an error, not a silent fallback to NIM. This prevents a typo from sending traffic to the wrong provider.

resolveProviderSelection() in packages/cli/src/config/config.ts builds a provider definition entirely from environment variables when the selected ID is not nvidia-nim and M31A_PROVIDER_BASE_URL is set.

2. Configure by environment ​

bash
export M31A_PROVIDER=local
export M31A_PROVIDER_BASE_URL=http://localhost:8000/v1
export M31A_PROVIDER_API_KEY=local-secret
export M31A_PROVIDER_MODEL=my-org/my-model
export M31A_PROVIDER_HEADERS='{"X-Tenant":"engineering"}'

Field mapping:

VariableProvider field
M31A_PROVIDERSelected provider ID.
M31A_PROVIDER_BASE_URLbaseUrl; trailing slashes are trimmed.
M31A_PROVIDER_API_KEYapiKey; sent as Authorization: Bearer ....
M31A_PROVIDER_MODELDefault model ID.
M31A_PROVIDER_HEADERSJSON object of extra headers.

Malformed header JSON is ignored rather than aborting startup. Base URLs must be http: or https:; other schemes are rejected. The provider ID is normalized to lowercase.

3. Or select with a flag ​

bash
m31a --provider local -p "Say hello" -o json

--provider overrides any saved selection for one invocation. If you prefer a persistent selection, the resolver reads provider or model.provider from settings and a providers map, but those keys are additive and not part of the generated settings schema. Environment variables are the most portable option.

4. NIM-specific overrides ​

If your endpoint is still NVIDIA NIM but hosted elsewhere, you can keep the built-in provider and change its defaults:

bash
export NVIDIA_NIM_BASE_URL=https://nim.example.com/v1
export NVIDIA_NIM_MODEL=nvidia/your-hosted-model
export NVIDIA_API_KEY=nvapi-...

These variables are consumed by packages/core/src/core/nvidiaNimContentGenerator.ts.

5. Verify the endpoint ​

The generator queries /models for the model list. Run:

bash
m31a --list-models
m31a models list --output-format json

Both should include my-org/my-model. If the endpoint does not implement /models, the list command may show only the configured default; a real request is the authoritative check.

Then send a one-shot prompt:

bash
m31a --provider local \
  -m my-org/my-model \
  -p "Reply with exactly: provider ok" \
  -o json > provider-check.json
node -e "const r=require('./provider-check.json'); if(r.error){console.error(r.error);process.exit(1)} console.log(r.response)"

6. Check the request shape ​

The generated request follows the OpenAI chat-completions convention:

json
{
  "model": "my-org/my-model",
  "messages": [
    {"role": "system", "content": "..."},
    {"role": "user", "content": "..."}
  ],
  "stream": true,
  "stream_options": {"include_usage": true},
  "max_tokens": 4096
}

Tool definitions are translated into OpenAI function entries with tool_choice: "auto". If your gateway rejects stream_options, set it up to accept the field or provide a compatibility shim; the generator always includes it for streaming calls.

7. Model config for the custom ID ​

Because M31A has no built-in metadata for your model, add a definition and a resolution if you want it to appear in the model dialog:

json
{
  "modelConfigs": {
    "modelDefinitions": {
      "my-org/my-model": {
        "displayName": "My Model",
        "tier": "custom",
        "family": "custom",
        "isVisible": true,
        "features": {"thinking": false}
      }
    },
    "modelIdResolutions": {
      "my-org/my-model": {"default": "my-org/my-model"}
    }
  }
}

See Model resolution for alias chains and fallback behavior. Model IDs containing a slash are passed through unchanged.

8. Troubleshooting ​

SymptomResolution
Unknown provider idThe ID must match M31A_PROVIDER or --provider.
404 on chat completionsEnsure the base URL includes the API version path.
401Check the API key and header configuration.
Empty model listThe endpoint may not implement /models; test with a prompt.
Tool-call errorsThe gateway must support OpenAI-style function tools.

Next steps ​

Built with VitePress. Powered by NVIDIA NIM.