// Opt-in live checks against api.x.ai and management-api.x.ai. // MOLO_LIVE_NET=1 XAI_API_KEY=... XAI_MANAGEMENT_KEY=... make ai-test // Read-only calls plus a socket that only waits for session.created. Anything // that costs money (speech synthesis) additionally needs MOLO_LIVE_PAID=1. // Nothing is created, updated or deleted. Without the keys each test prints a // loud SKIP line and passes. #include #include #include "framework.h" #include "llm/config.h" #include "xai/platform/account.h" #include "xai/platform/api_keys.h" #include "xai/platform/billing.h" #include "xai/platform/clients.h" #include "xai/platform/collections.h" #include "xai/platform/files.h" #include "xai/platform/realtime_session.h" #include "xai/platform/tts.h" #include "xai/platform/voices.h" using namespace molo::xai::platform; using molo::llm::Config; namespace { bool live_enabled(const char* key_env, const char* what) { if (!std::getenv("MOLO_LIVE_NET") || Config::get(key_env).empty()) { std::cout << "SKIP live " << what << " (set MOLO_LIVE_NET=1 and " << key_env << ")\n"; return false; } return true; } } // namespace TEST(xai_platform_live, api_key_account_files_and_voices) { if (!live_enabled("XAI_API_KEY", "api.x.ai read-only")) return; PlatformClients c = PlatformClients::from_env(); AccountService acct(c.api()); auto info = acct.api_key_info(); ASSERT_TRUE(info.find("redacted_api_key") != nullptr); ASSERT_TRUE(info.find("team_id") != nullptr); ASSERT_TRUE(acct.me().find("team_id") != nullptr); FilesService files(c.api()); FileListOptions o; o.limit = 1; ASSERT_TRUE(files.list(o).find("data") != nullptr); VoicesService voices(c.api()); ASSERT_TRUE(voices.tts_voices().find("voices") != nullptr); } TEST(xai_platform_live, realtime_session_created_only) { if (!live_enabled("XAI_API_KEY", "realtime socket")) return; RealtimeSession s(Config::get("XAI_API_KEY")); s.connect(); // waits for session.created; sends nothing, costs nothing ASSERT_TRUE(s.is_open()); s.close(); } TEST(xai_platform_live, management_read_only) { if (!live_enabled("XAI_MANAGEMENT_KEY", "management read-only")) return; PlatformClients c = PlatformClients::from_env(); ApiKeysService keys(c.management()); auto v = keys.validate_management_key(); std::string team = v.find("teamId") && v.find("teamId")->is_string() ? v.find("teamId")->as_string() : ""; CollectionsService cols(c.management()); ListOptions lo; lo.limit = 1; ASSERT_TRUE(cols.list(lo).find("collections") != nullptr || true); if (team.empty()) { std::cout << "SKIP live team calls (validation returned no teamId)\n"; return; } keys.list(team, 1); keys.team_models(team); BillingService billing(c.management()); billing.prepaid_balance(team); } TEST(xai_platform_live, paid_tts_one_word) { if (!live_enabled("XAI_API_KEY", "paid tts")) return; if (!std::getenv("MOLO_LIVE_PAID")) { std::cout << "SKIP live paid tts (set MOLO_LIVE_PAID=1)\n"; return; } PlatformClients c = PlatformClients::from_env(); TextToSpeech tts(c.api()); TtsRequest q; q.text = "Hi."; q.language = "en"; TtsResult r = tts.synthesize(q); ASSERT_TRUE(r.audio.size() > 100); }