nimclient

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

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 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).

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.

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