File size: 3,175 Bytes
5024202
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env python3
# SPDX-FileCopyrightText: 2026 Shamiur Rashid Sunny
# SPDX-License-Identifier: AGPL-3.0-only
"""Probe NVIDIA NIM to verify API key + discover tool-calling models.

Usage:
    export NVIDIA_API_KEY=nvapi-...
    python scripts/probe_nvidia.py
"""

import os
import sys

import httpx


BASE = "https://integrate.api.nvidia.com/v1"


def main():
    key = os.getenv("NVIDIA_API_KEY", "").strip()
    if not key:
        print("ERROR: NVIDIA_API_KEY not set")
        print("Run: export NVIDIA_API_KEY=nvapi-...")
        return 1

    print("=" * 60)
    print(" NVIDIA NIM Probe")
    print("=" * 60)
    print()

    print("[1] Fetching model list...")
    try:
        r = httpx.get(
            BASE + "/models",
            headers={"Authorization": "Bearer " + key},
            timeout=15.0,
        )
    except Exception as e:
        print("    FAIL: " + type(e).__name__ + ": " + str(e))
        return 1

    print("    HTTP " + str(r.status_code))
    if r.status_code != 200:
        print("    Body: " + r.text[:400])
        return 1

    try:
        data = r.json()
        models = [m.get("id") for m in data.get("data", [])]
    except Exception as e:
        print("    FAIL to parse: " + str(e))
        return 1

    print("    Total models: " + str(len(models)))
    print()

    print("[2] Tool-calling candidates:")
    known = [
        "meta/llama-4-maverick-17b-128e-instruct",
        "meta/llama-4-scout-17b-16e-instruct",
        "mistralai/mistral-small-3.2-24b-instruct-2506",
        "nvidia/llama-3.1-nemotron-70b-instruct",
        "meta/llama-3.3-70b-instruct",
        "meta/llama-3.1-70b-instruct",
    ]
    found = []
    for k in known:
        if k in models:
            found.append(k)
            print("    [OK]      " + k)
        else:
            print("    [MISSING] " + k)
    print()

    if found:
        print("[3] Recommended first: " + found[0])
    else:
        print("[3] No known tool-calling model present in your account.")
        print("    Check https://build.nvidia.com/models")
    print()

    if found:
        print("[4] Test completion with " + found[0] + "...")
        try:
            r = httpx.post(
                BASE + "/chat/completions",
                headers={
                    "Authorization": "Bearer " + key,
                    "Content-Type": "application/json",
                },
                json={
                    "model": found[0],
                    "messages": [{"role": "user", "content": "Say hi in one word."}],
                    "max_tokens": 30,
                },
                timeout=30.0,
            )
            print("    HTTP " + str(r.status_code))
            if r.status_code == 200:
                d = r.json()
                content = d["choices"][0]["message"].get("content", "")
                print("    Response: " + content[:100])
            else:
                print("    Body: " + r.text[:400])
        except Exception as e:
            print("    FAIL: " + type(e).__name__ + ": " + str(e))

    print()
    print("=" * 60)
    print(" Done.")
    return 0


if __name__ == "__main__":
    sys.exit(main())