Skip to content

How do I use GLM 5 on Amazon Bedrock as the model behind Claude Code?

4 minute read
Content level: Intermediate
0

Claude Code's native Amazon Bedrock mode is built for Anthropic models and can't reach Z.AI's GLM 5. This article shows how to put a small Anthropic-compatible proxy between Claude Code and Amazon Bedrock so GLM 5 answers your requests while inference stays billed to your own AWS account and Region.

Issue

You use Claude Code as your coding interface and you want a lower-cost model to answer some of the requests — specifically Z.AI's GLM 5, which is available in Amazon Bedrock — while keeping the work inside your own AWS account. When you try Claude Code's native Amazon Bedrock mode (CLAUDE_CODE_USE_BEDROCK=1), it does not work with GLM.

Short answer

Claude Code speaks the Anthropic Messages API; GLM 5 on Amazon Bedrock is served through the Converse API. The native Bedrock mode is built for Anthropic models (it uses InvokeModel with the Anthropic schema), so it cannot reach GLM. Put a small Anthropic-compatible proxy between Claude Code and Amazon Bedrock to translate the requests, and point Claude Code at the proxy with environment variables.

Resolution

1. Enable and verify GLM 5

Enable model access in the Amazon Bedrock console (Model access → Z.AI → GLM 5) in a supported Region such as us-west-2. Confirm it responds through Converse:

aws bedrock-runtime converse \
  --region us-west-2 \
  --model-id zai.glm-5 \
  --messages '[{"role":"user","content":[{"text":"Reply with: ok"}]}]' \
  --inference-config '{"maxTokens":5}'

2. Run LiteLLM as the translation proxy

Use LiteLLM, which exposes an Anthropic POST /v1/messages endpoint and routes to Bedrock Converse. AWS publishes a reference architecture built on LiteLLM — Guidance for Multi-Provider Generative AI Gateway on AWS — for a production deployment on ECS or EKS. Pin a current, known-good release. (An OpenAI-compatible-only proxy will not work — Claude Code sends the Anthropic format. Bifrost is one alternative gateway that also offers an Anthropic endpoint.)

Configure two routes in config.yaml:

model_list:
  - model_name: glm-5
    litellm_params:
      model: bedrock/converse/zai.glm-5
      aws_region_name: os.environ/AWS_REGION
  - model_name: glm-flash
    litellm_params:
      model: bedrock/converse/zai.glm-4.7-flash
      aws_region_name: os.environ/AWS_REGION

LiteLLM signs Bedrock calls with your standard AWS credential chain, so GLM 5 inference is billed to your account and stays in your Region.

3. Point Claude Code at the proxy

export ANTHROPIC_BASE_URL="http://localhost:4000"
export ANTHROPIC_AUTH_TOKEN="<your-proxy-key>"
export ANTHROPIC_MODEL="glm-5"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="glm-flash"

Run claude. GLM 5 now answers the calls.

Common problems and how to fix them

Background calls still reach the Anthropic API. Claude Code uses a smaller model for background tasks (titles, context estimation). If you set only ANTHROPIC_MODEL, those calls go to the Anthropic API. Fix: set ANTHROPIC_DEFAULT_HAIKU_MODEL to a proxy route.

Long edits get cut off. GLM 4.7 caps output at 4K tokens. Use GLM 5 (128K output) as the primary model; use the lighter models only for the background route.

A 400 error mentioning a beta header. Claude Code sends request headers Amazon Bedrock does not accept. Use your proxy's option to filter or disable experimental beta headers on the Bedrock path.

File edits stall. Claude Code depends on tool calls. Test one end-to-end tool-use exchange through the proxy before you rely on it.

Data handling

GLM 5 runs on AWS-managed infrastructure in your selected Region and is available for in-Region inference. Under the default Amazon Bedrock data-retention mode, prompts and outputs are not shared with the model provider and are not used for training. For zero retention, set the data-retention mode to none. See Data protection in Amazon Bedrock.

Good to know

  • Use GLM 5 as a lower-cost lane for work that is cheap to verify (boilerplate, mechanical refactors, first-draft tests, triage). Keep architecture and production-critical work on your primary model.
  • Pointing Claude Code at a proxy is documented; routing to a non-Anthropic model is supported by the proxy project, not by Anthropic. Pin a known-good Claude Code version.

Related


Shared by Bharadwaz Kari as a personal community contribution — my own experience and opinions, not official AWS guidance.