Docs · Provider

Grok in Claude Code, Codex, Gemini CLI and OpenCode

xAI serves its Grok models on three APIs at once: OpenAI Chat Completions, OpenAI Responses and Anthropic Messages. Add an xAI API key to packinggoods once, and Claude Code, Codex, Gemini CLI, OpenCode and every other agent you connect can use Grok through packinggoods’s local gateway at 127.0.0.1:3425, each agent with a model of its own.

Add xAI

  1. Get a keyMake one on console.x.ai.
  2. Add the providerIn packinggoods’s Providers tab, press + Add provider, pick xAI, paste the key and save. packinggoods asks xAI which models the key can use.
  3. Pick it for an agentIn the Agents tab, click the model on the agent’s row and choose a Grok model such as grok-4.7.
Terminal
packinggoods provider add xai xai-…
packinggoods provider test xai

Model ids in packinggoods are provider/model, so xAI’s read xai/grok-4.7: the provider, then xAI’s own id. The key is kept in packinggoods’s settings; packinggoods doesn’t take it from your shell.

Endpoints

APIBase URLUsed for
Chat Completionshttps://api.x.ai/v1the model list, OpenCode’s requests, and every request packinggoods translates, Gemini CLI’s among them
Responseshttps://api.x.ai/v1Codex’s requests, and web search that xAI runs itself
Anthropic Messageshttps://api.x.aiClaude Code’s requests

An agent whose API xAI serves is passed on to that API. When packinggoods has to translate, it uses Chat Completions: it keeps Responses first only for OpenAI’s own models at OpenAI, and Messages first only for Claude models, and Grok is neither.

Model list

packinggoods fetches the list from xAI, at https://api.x.ai/v1/models, so agents see the models your key can use. Names, reasoning levels and prices come from models.dev’s xai catalog. Pick the models agents see in the provider’s model list, or from the terminal:

Terminal
packinggoods provider models xai +grok-4.7
packinggoods provider refresh-every xai 1d

In each agent

Terminal
packinggoods claude xai/grok-4.7
packinggoods codex xai/grok-4.7
packinggoods gemini model xai/grok-4.7
packinggoods opencode xai/grok-4.7

Grok Build, xAI’s own CLI, can take packinggoods’s models too: packinggoods adds them to ~/.grok/config.toml, so they join its /model picker.

What packinggoods fixes for xAI

xAI’s API turns away a few things that agents send. packinggoods changes them on the way, on requests it passes on and on those it translates alike, so the agent never sees these errors:

Reasoning

Cache, cost and usage

Several keys and failover

One xAI provider can hold several keys: press Add another key under it, or paste several at once. Requests go to the first key that’s on, and when it runs out or is rate limited the next one takes over.

Terminal
packinggoods provider spend-cap xai <key> 20 month
packinggoods provider key-balance xai <key> 25
packinggoods provider fallback xai deepseek/deepseek-v4-pro

Troubleshooting

FAQ

How do I use Grok in Claude Code?

Add your xAI API key in packinggoods (Providers, Add provider, xAI), then pick a Grok model such as grok-4.7 on Claude Code’s row, or run packinggoods claude xai/grok-4.7. Claude Code’s requests go through packinggoods’s gateway to xAI’s Anthropic Messages endpoint, https://api.x.ai.

Can Codex use Grok 4?

Yes. xAI serves the Responses API that Codex speaks, so packinggoods codex xai/grok-4.7 sends Codex’s requests to https://api.x.ai/v1 as they are, with what xAI would refuse fixed on the way: tool schemas, a tool choice with no tools, and whole numbers Grok writes as 2500.0.

Can Gemini CLI and OpenCode use Grok?

Yes. Gemini CLI speaks Google’s API, so packinggoods translates its requests to xAI’s Chat Completions and the replies back. OpenCode speaks Chat Completions, so its requests go to xAI as they are. Run packinggoods gemini model xai/grok-4.7 or packinggoods opencode xai/grok-4.7.

Does web search work with Grok?

Yes. Codex’s web search is run by xAI itself on its Responses API. For Claude Code, Gemini CLI and OpenCode, packinggoods gives the model its own search tool, answered by the searcher chosen in Settings, or by one packinggoods picks.

Why did Codex fail after switching from GPT to Grok mid-conversation?

xAI can’t read reasoning that another vendor sealed, and answers “Could not decrypt the provided encrypted_content”. packinggoods asks again without those items and leaves them out for the rest of the conversation.

Does packinggoods show my xAI balance?

No. The Usage tab counts tokens, cache and cost for every Grok call, priced from models.dev, but packinggoods reads no balance from xAI. You can type the balance in with packinggoods provider key-balance, and the Usage page shows it less what packinggoods has priced since.

By provider: DeepSeek · Kimi and Kimi Code · GLM Coding Plan · Volcengine Ark · Tencent Cloud · Baidu Qianfan · SiliconFlow · ModelScope · Huawei Cloud MaaS · Xiaomi MiMo · StepFun · LongCat · Qwen · MiniMax · Anthropic · OpenAI · Gemini · Mistral · OpenRouter · GitHub Copilot · Ollama

Every agent: Models in Claude Code, Models in Codex, Models in Gemini CLI, Models in OpenCode. Ask on Discord if you get stuck.