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:
- an explicit provider ID from
--providerorM31A_PROVIDER; - a saved selection from settings;
- the built-in
nvidia-nimdefault.
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
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:
| Variable | Provider field |
|---|---|
M31A_PROVIDER | Selected provider ID. |
M31A_PROVIDER_BASE_URL | baseUrl; trailing slashes are trimmed. |
M31A_PROVIDER_API_KEY | apiKey; sent as Authorization: Bearer .... |
M31A_PROVIDER_MODEL | Default model ID. |
M31A_PROVIDER_HEADERS | JSON 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
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:
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:
m31a --list-models
m31a models list --output-format jsonBoth 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:
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:
{
"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:
{
"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
| Symptom | Resolution |
|---|---|
Unknown provider id | The ID must match M31A_PROVIDER or --provider. |
| 404 on chat completions | Ensure the base URL includes the API version path. |
| 401 | Check the API key and header configuration. |
| Empty model list | The endpoint may not implement /models; test with a prompt. |
| Tool-call errors | The gateway must support OpenAI-style function tools. |
Next steps
- Read Authentication for key storage.
- Read Model resolution.
- Read Environment variables for the full list.