Repository navigation
feat(models): add a native xAI provider - #3561
bwong05umd wants to merge 4 commits into
Conversation
Add `xAI` to the ModelProvider enum with an optional `xAI` block (baseUrl, temperature, topP, maxTokens, timeout) that mirrors the Mistral block, plus a CEL rule that rejects the block on any other provider. Add the matching `ADKXAI` runtime message to the ADK config protobuf as oneof field 21. Regenerate deepcopy code, the Helm-packaged CRDs, and the Go and Python protobuf output. Refs kagent-dev#3543 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Benjamin Wong <wongbency05@gmail.com>
xAI serves an OpenAI-compatible chat completions API, so both runtimes reuse their OpenAI clients with xAI defaults: base URL https://api.x.ai/v1, credential XAI_API_KEY, and XAI_API_BASE as an override. The token limit is sent as max_completion_tokens because xAI marks max_tokens as deprecated. Tests post a chat completion to a local server, with no live key, and cover key and base URL precedence and passthrough. The shared runtime config fixture gains an xai sub-agent so both runtimes keep parsing it. Refs kagent-dev#3543 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Benjamin Wong <wongbency05@gmail.com>
…talog Translate an xAI ModelConfig into the xai runtime config, mount its API key Secret as XAI_API_KEY, and bind the credential to https://api.x.ai so the egress gateway injects it. Allow https://api.x.ai:443 in the agent egress policy unless a custom base URL is set. Report traces as x_ai, the GenAI semantic-convention value, instead of openai. List xAI as a supported provider with Grok model suggestions from docs.x.ai, with grok-4.7 first as the default. Refs kagent-dev#3543 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Benjamin Wong <wongbency05@gmail.com>
Show xAI with links to its console and model docs, and allow token passthrough for it, as the CRD does. Add a providers.xAI Helm entry and an install example. Refs kagent-dev#3543 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Benjamin Wong <wongbency05@gmail.com>
|
I did initial testing and it appears to do the right thing. Are you able to deploy end to end @bwong05umd ? |
Thanks for testing! Yes, I can deploy it end to end. My plan is to run it on kind tomorrow using the repo’s mockllm through baseUrl, since I don’t have a paid xAI key, and post the results here. I’ll check the Secret, compiled runtime config, credential delivery, the agent’s request and response, and the trace’s provider name. That won’t cover the live xAI API, so did your testing hit the real API? In the meantime, is there a maintainer who can approve the CI workflows? |
|
Sorry for the delay. Getting the local stack running took longer than I expected. I deployed this PR end to end on kind (
One thing I noticed: the traces include the model but not Not covered: the live xAI API and the default |
|
This pull request has been marked as stale because of no activity in the last 15 days. It will be closed in the next 5 days unless it is tagged "no stalebot" or other activity occurs. |
|
This pull request has been closed after 15 days of inactivity and an additional 5 days after being marked as stale. |
Summary
Adds a native
xAImodel provider, following the Mistral pattern from #2406. xAI's API is OpenAI-compatible (POST /v1/chat/completionswith a Bearer key), so both runtimes reuse their OpenAI clients with xAI defaults.This resolves the three gaps the issue lists:
provider: xAIreacheshttps://api.x.ai/v1withXAI_API_KEY, andXAI_API_BASEoverrides the URL. Users no longer need an OpenAI config with a hand-written base URL.https://api.x.ai:443, or only the configured base URL when one is set. Credentials are bound to that origin withauthorization: Bearer.ProviderNamereturnsconv.GenAIProviderNameXAI(x_ai) instead ofopenai.Commits, in review order:
feat(api): thexAIenum value, anXAIConfigblock (baseUrl,temperature,topP,maxTokens,timeout) with a CEL rule, andADKXAIas oneof field 21. Generated output is included;make proto-breakingpasses.feat(adk): GoXAIModeland PythonKAgentXAILlmwrap the OpenAI clients. Both send the token limit asmax_completion_tokens, because xAI's chat completions reference marksmax_tokensas deprecated.feat(models): translation, Secret mounting, credential binding, egress, tracing, and a static catalog. Every model ID comes from docs.x.ai, whose per-model pages each list function calling.grok-4.7comes first, as the default.feat(ui): the model form's display name, docs links and token passthrough, plus aproviders.xAIHelm entry.Fixes #3543
Test plan
Following the issue's test plan, with no live key:
POST /v1/chat/completionsforgrok-4.7withAuthorization: Bearer <key>, and the body setsmax_completion_tokensbut notmax_tokens. This is covered in Go (xai_test.go) and Python (test_xai.py).https://api.x.ai:443, and compiles a runtime config whose provider isxai. Covered bycompiler_test.go,builder_test.goandmodel_test.go.ProviderName(ModelProviderXAI)isx_ai(otel_test.go).Run locally:
make -C go lint: 0 issues.make proto-lint proto-generate proto-breaking, andmake controller-manifestswith no drift.go testforapi/...,adk/...,core/internal/translator/...,core/internal/service/modelandcore/internal/grpcserver.kagent-adkunit suite, andruff format/ruff check.yarn typecheck,yarn lint(no new warnings) andyarn test.helm templatewithproviders.default=xAI, including a renderedconfig:block.Not run locally, left for CI:
make testgenerates.helm unittest.Notes for reviewers
AI disclosure: I wrote this change with an AI coding assistant (Claude Code). I reviewed every change, ran the checks above, and can explain and stand behind the code.
🤖 Generated with Claude Code