Skip to content

feat: added support for z.ai coding plan via API as an alternative to anthropic#89

Open
mohitsinghdz wants to merge 1 commit intoKeygraphHQ:mainfrom
mohitsinghdz:main
Open

feat: added support for z.ai coding plan via API as an alternative to anthropic#89
mohitsinghdz wants to merge 1 commit intoKeygraphHQ:mainfrom
mohitsinghdz:main

Conversation

@mohitsinghdz
Copy link

Summary

Added support for Z.AI's GLM coding plan as an alternative LLM provider, allowing Shannon to run penetration tests using Z.AI's Anthropic-compatible API endpoint instead of direct Anthropic API or the router-based multi-model setup.

Changes

1. New GLM=true CLI flag (shannon)

  • Added GLM=true option to the shannon CLI script
  • When enabled, configures the Anthropic SDK to route through Z.AI's Anthropic-compatible endpoint (https://api.z.ai/api/anthropic)
  • Sets ANTHROPIC_AUTH_TOKEN from ZAI_API_KEY for authentication
  • Handles mutual exclusivity with ROUTER=true (GLM takes priority with a warning)
  • Added validation that ZAI_API_KEY is set when GLM=true
  • Added fallback placeholder ANTHROPIC_API_KEY="glm-mode" to satisfy SDK initialization

2. Router config update (configs/router-config.json)

  • Added zai provider configuration pointing to https://api.z.ai/api/paas/v4/chat/completions
  • Configured with max_completion_tokens: 16384 transformer
  • Uses $ZAI_API_KEY environment variable for authentication

3. Docker environment passthrough (docker-compose.yml)

  • Added ZAI_API_KEY to both shannon-worker and claude-code-router services

4. GLM detection utility (src/ai/router-utils.ts)

  • Added isGlmDirectMode() function to detect when Z.AI direct mode is active (checks if ANTHROPIC_BASE_URL contains api.z.ai)
  • Updated isRouterMode() to exclude GLM direct mode, preventing it from being incorrectly treated as router mode

5. Environment example (.env.example)

  • Added OPTION 3: Z.AI GLM Mode section with ZAI_API_KEY placeholder
  • Documented the GLM=true flag usage

Usage

# Set in .env
ZAI_API_KEY=your-zai-api-key

# Run with GLM mode
./shannon start URL=https://example.com REPO=/path/to/repo GLM=true

Files Changed

File Changes
shannon +22 lines — CLI flag parsing, validation, endpoint configuration
src/ai/router-utils.ts +9/-2 — GLM detection + router mode fix
configs/router-config.json +9 — Z.AI provider config
docker-compose.yml +2 — ZAI_API_KEY env passthrough
.env.example +7 — Documentation and example

Test Plan

  • Run ./shannon start URL=<url> REPO=<path> GLM=true with a valid ZAI_API_KEY
  • Verify error when GLM=true is set without ZAI_API_KEY
  • Verify GLM=true takes priority over ROUTER=true with a warning
  • Confirm isGlmDirectMode() returns true when Z.AI endpoint is configured
  • Confirm isRouterMode() returns false in GLM direct mode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant