Package net.thevpc.naru.ext.models.xai
Class NaruXaiProvider
java.lang.Object
net.thevpc.naru.api.model.AbstractNaruModelProvider
net.thevpc.naru.ext.models.openapi.AbstractOpenAICompatProvider
net.thevpc.naru.ext.models.xai.NaruXaiProvider
- All Implemented Interfaces:
NaruModelProvider,net.thevpc.nuts.spi.NComponent
-
Field Summary
Fields inherited from class net.thevpc.naru.ext.models.openapi.AbstractOpenAICompatProvider
protocols -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringbaseUrl(NaruSession session) Fallback base url when<name>.urlconfig is not set.fetchPrepaidBalanceCents(String managementApiKey, String teamId, NaruSession session) Checks prepaid credit balance via the xAI Management API.booleanhasNoCredits(net.thevpc.nuts.net.NHttpResponse response) Zero-balance / no-funds detection without a separate Management API key: xAI's inference endpoints return a distinguishable 403 with code "permission-denied" and a message mentioning credits/licenses when a team has no funds.protected NaruModelCapabilitiesresolveCapabilities(String modelName, NaruSession session) Statically maps capabilities since cloud-hosted capabilities cannot be polled natively.Methods inherited from class net.thevpc.naru.ext.models.openapi.AbstractOpenAICompatProvider
chatPath, connectTimeout, createProtocol, fetchLiveModelIds, findModelIds, findModelIdsWithLiveFallback, getProtocol, isApiKeySet, isReachable, modelsPath, readTimeoutMethods inherited from class net.thevpc.naru.api.model.AbstractNaruModelProvider
apiKey, defaultEnvKey, getParam, getParamNames, getSecureParam, isEnabled, name, onParamChanged, setEnabled, setParamMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.thevpc.naru.api.model.NaruModelProvider
installModel, isAvailable, isSupportedInstallModel, isSupportedPsModel, isSupportedUninstallModel, isSupportedUnloadModel, psModel, uninstallModel, unloadModel
-
Constructor Details
-
NaruXaiProvider
public NaruXaiProvider()
-
-
Method Details
-
baseUrl
Description copied from class:AbstractOpenAICompatProviderFallback base url when<name>.urlconfig is not set.- Specified by:
baseUrlin classAbstractOpenAICompatProvider
-
resolveCapabilities
Description copied from class:AbstractOpenAICompatProviderStatically maps capabilities since cloud-hosted capabilities cannot be polled natively.- Specified by:
resolveCapabilitiesin classAbstractOpenAICompatProvider
-
fetchPrepaidBalanceCents
Checks prepaid credit balance via the xAI Management API. Requires a separate management key with "Management Keys Read" permission (console.x.ai > Settings) — NOT the same as XAI_API_KEY/GROK_API_KEY used for inference.- Parameters:
managementApiKey- the management keyteamId- the team ID (visible in the console URL, e.g. console.x.ai/team/{teamId})- Returns:
- balance in USD cents (negative = credit remaining, per xAI's sign convention seen in their docs example: "total": {"val": "-1000"} means $10.00 available), or null if the check failed
-
hasNoCredits
public boolean hasNoCredits(net.thevpc.nuts.net.NHttpResponse response) Zero-balance / no-funds detection without a separate Management API key: xAI's inference endpoints return a distinguishable 403 with code "permission-denied" and a message mentioning credits/licenses when a team has no funds. Not as precise as the Management API (can't show exact balance), but sufficient to decide whether to surface this provider to the user at all.
-