Class NaruXaiProvider

All Implemented Interfaces:
NaruModelProvider, net.thevpc.nuts.spi.NComponent

public class NaruXaiProvider extends AbstractOpenAICompatProvider
  • Constructor Details

    • NaruXaiProvider

      public NaruXaiProvider()
  • Method Details

    • baseUrl

      protected String baseUrl(NaruSession session)
      Description copied from class: AbstractOpenAICompatProvider
      Fallback base url when <name>.url config is not set.
      Specified by:
      baseUrl in class AbstractOpenAICompatProvider
    • resolveCapabilities

      protected NaruModelCapabilities resolveCapabilities(String modelName, NaruSession session)
      Description copied from class: AbstractOpenAICompatProvider
      Statically maps capabilities since cloud-hosted capabilities cannot be polled natively.
      Specified by:
      resolveCapabilities in class AbstractOpenAICompatProvider
    • fetchPrepaidBalanceCents

      public Long fetchPrepaidBalanceCents(String managementApiKey, String teamId, NaruSession session)
      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 key
      teamId - 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.