nimclient

package
v0.206.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package nimclient calls an OpenAI-compatible NVIDIA NIM endpoint — either NVIDIA's hosted build.nvidia.com API (https://integrate.api.nvidia.com/v1, authenticated with an nvapi- key) or a self-hosted NIM container (http://host:8000/v1, no key). It is the harness's EXPLICIT remote-model tool: the local Gemma cascade and its sacred GBNF grammar path are untouched, and NIM calls never enter the savings ledger (they are deliberate experiments / escalations, not defer-avoidance). Pure net/http; no SDK.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APIKeyFromEnv

func APIKeyFromEnv() string

APIKeyFromEnv reads the NIM key from env ONLY (never from a config file, so a secret never lands in a tracked file): NVIDIA_API_KEY first, then NGC_API_KEY (the name NVIDIA's own NIM docs use). Empty = no key (a self-hosted NIM is keyless). The single source of truth for both the CLI and MCP paths.

func BaseAllowed added in v0.206.0

func BaseAllowed(base, configured string, extra []string) (ok bool, why string)

BaseAllowed reports whether a caller-named base is one offload_nim may target (security standard L5, register S-30): NVIDIA's hosted API (IsHostedNVIDIA), the configured endpoint, or an entry of the operator's extra list. A base matches an entry when scheme, host (case-insensitive, trailing root dot dropped) and port are equal — the default port made explicit — and the entry's path is a prefix of the base's path on a segment boundary. why names the rule that matched, or the reason nothing did.

func IsHostedNVIDIA

func IsHostedNVIDIA(base string) bool

IsHostedNVIDIA reports whether base targets NVIDIA's hosted API (which requires a key), as opposed to a self-hosted NIM container (which is keyless).

It decides who receives the key, so it matches the parsed HOST exactly: https, no userinfo, the default port, and a host that IS api.nvidia.com or a DNS subdomain of it (integrate.api.nvidia.com, ai.api.nvidia.com), compared case-insensitively with a trailing root dot dropped. Until 0.143.1 it was a substring test on the whole URL, so a caller-supplied base such as https://attacker.example/integrate.api/v1 or https://api.nvidia.com.attacker.example/v1 — one prompt-injected offload_nim call — received NVIDIA_API_KEY as a Bearer token.

func KeyForBase

func KeyForBase(base string) string

KeyForBase returns the API key to transmit to base: the env key for NVIDIA's hosted API, and "" for ANY other base. This is a security boundary, not just a convenience — the NVIDIA key is only valid on NVIDIA's endpoints, so silently sending it to a user-supplied --base (a typo, a self-hosted NIM, or a third party) would leak the secret over the wire for no benefit. A self-hosted NIM is keyless by design; both the CLI and MCP paths resolve the key through here.

Types

type ChatResult

type ChatResult struct {
	Content          string
	ReasoningContent string
	Model            string
	TokensIn         int
	TokensOut        int
	Truncated        bool
}

ChatResult holds the model output and per-call telemetry. ReasoningContent is populated for reasoning models that emit a separate reasoning_content field; Content is the user-facing answer (which can be empty if the response was cut at max_tokens mid-thought — Truncated then signals it).

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client targets one OpenAI-compatible base (".../v1"). apiKey may be empty for a keyless self-hosted NIM; when set it is sent as a Bearer token.

func New

func New(base, apiKey string, timeout time.Duration) *Client

New builds a client. base should include the API version segment (e.g. "https://integrate.api.nvidia.com/v1"). A trailing slash is trimmed.

A hosted NVIDIA base dials only public addresses (netguard.PublicTransport, register SF-01): the key goes to that host, so a DNS answer that points api.nvidia.com at a private, loopback or tailnet address must not carry it there. Self-hosted NIM bases on the LAN or the tailnet keep the plain transport, since they are private by design and keyless.

func (*Client) Chat

func (c *Client) Chat(ctx context.Context, model, system, user string, maxTokens int, temperature float64) (ChatResult, error)

Chat sends system (optional) + user to model and returns the answer + telemetry.

func (*Client) ListModels

func (c *Client) ListModels(ctx context.Context) ([]string, error)

ListModels returns the sorted model ids the endpoint advertises at /models.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL