Claude-skill-registry glm-coding

This skill provides specialized knowledge for integrating and using GLM-4.7 Coding Plan API (智谱编程套餐). Use this skill when working with GLM-4.7 for prompt optimization, code generation, or technical documentation tasks. GLM-4.7 uses a unique response format with reasoning_content field and requires special endpoint handling.

install
source · Clone the upstream repo
git clone https://github.com/majiayu000/claude-skill-registry
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/glm-coding" ~/.claude/skills/majiayu000-claude-skill-registry-glm-coding && rm -rf "$T"
manifest: skills/data/glm-coding/SKILL.md
source content

GLM-4.7 Coding Plan Integration

This skill provides specialized knowledge for integrating and using GLM-4.7 Coding Plan API (智谱编程套餐) from Zhipu AI (智谱AI).

Purpose

GLM-4.7 Coding Plan is a specialized OpenAI-compatible API designed for programming and code-related tasks. This skill covers:

  • API integration with correct endpoint format
  • Response format handling (
    reasoning_content
    vs
    content
    )
  • Performance characteristics and optimization strategies
  • Best practices for prompt optimization

When to Use This Skill

Use this skill when:

  • Integrating GLM-4.7 Coding Plan API into applications
  • Troubleshooting GLM API connection or response issues
  • Optimizing prompts for video generation or other tasks
  • Comparing GLM with other AI providers (DeepSeek, etc.)

API Integration

Endpoint Format (⚠️ Critical Difference)

GLM-4.7 Coding Plan uses a non-standard endpoint format:

Base URL: https://open.bigmodel.cn/api/coding/paas/v4
Full Endpoint: https://open.bigmodel.cn/api/coding/paas/v4/chat/completions

Key Difference: No

/v1
prefix, directly
/chat/completions

Example (openaiClient.js):

// ❌ Wrong: Standard OpenAI format
const baseURL = 'https://api.openai.com/v1';
const endpoint = '/chat/completions';

// ✅ Correct: GLM Coding Plan format
const baseURL = 'https://open.bigmodel.cn/api/coding/paas/v4';
const endpoint = '/chat/completions';  // No /v1 prefix
const url = `${baseURL}${endpoint}`;  // Final: https://open.bigmodel.cn/api/coding/paas/v4/chat/completions

Response Format Handling (⚠️ Critical)

GLM-4.7 returns content in

reasoning_content
field, NOT the standard OpenAI
content
field:

// Response structure from GLM-4.7
{
  "choices": [{
    "message": {
      "content": "",           // ⚠️ Empty
      "reasoning_content": "Actual content here",  // ✅ Real content
      "role": "assistant"
    }
  }]
}

// ❌ Wrong: Only reads content field
const result = response.data.choices[0].message.content;
// Result: "" (empty string)

// ✅ Correct: Compatible with both formats
const message = response.data.choices[0].message;
const result = message.content || message.reasoning_content || '';

Implementation Example (openaiClient.js - Lines 111, 170):

// In optimizePrompt method (Line 111)
const message = response.data.choices[0].message;
const result = message.content || message.reasoning_content || '';

// In testConnection method (Line 170)
const message = response.data.choices[0].message;
const result = message.content || message.reasoning_content || '';

API Key Format

GLM API keys use a special format:

{id}.{key}

Example:

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Storage (per-service in localStorage):

// Store API keys per service
const apiKeys = JSON.parse(localStorage.getItem('winjin-openai-keys') || '{}');
apiKeys['glm_coding'] = userApiKey;
localStorage.setItem('winjin-openai-keys', JSON.stringify(apiKeys));

// Retrieve
const apiKeys = JSON.parse(localStorage.getItem('winjin-openai-keys') || '{}');
const apiKey = apiKeys['glm_coding'] || '';

Performance Characteristics

Based on production testing (10 optimization requests):

MetricValueNotes
Response Time~60 secondsSignificantly slower than other providers
Token Usage~2,339 tokens/requestHigher consumption for optimization tasks
Success Rate100% (10/10)Reliable when format is handled correctly
ModelGLM-4.7 (only option)Coding Plan has only one model

Timeout Configuration:

// Set longer timeout for GLM requests (120 seconds)
const response = await axios.post(url, body, {
  timeout: 120000,  // 2 minutes
  headers: {
    'Authorization': `Bearer ${apiKey}`,
    'Content-Type': 'application/json'
  }
});

Use Cases

1. Prompt Optimization (picture-book style)

Tested and working - GLM-4.7 successfully optimizes prompts for video generation:

Request Example:

{
  "base_url": "https://open.bigmodel.cn/api/coding/paas/v4",
  "api_key": "your_api_key_here",
  "model": "GLM-4.7",
  "prompt": "@b2e75200f.pennypuf 在海边玩耍",
  "style": "picture-book",
  "context": {
    "target_duration": 10,
    "characters": []
  }
}

Response Example:

{
  "success": true,
  "data": {
    "optimized_prompt": "卡通绘本风格的视频,一只拟人化的海鹦鹉正站在海边湿润的岩石上...",
    "meta": {
      "model_used": "GLM-4.7",
      "style": "picture-book",
      "tokens_used": 2311
    }
  }
}

2. Code Generation and Optimization

GLM-4.7 is designed for programming tasks:

  • Code review and refactoring
  • Bug fixing and optimization
  • Technical documentation generation

3. Technical Documentation

Auto-generating documentation from code:

  • API documentation
  • Code comments and explanations
  • Architecture descriptions

Known Limitations

⚠️ Performance Issues:

  • Slow response time (~60 seconds per request)
  • Not suitable for real-time interactions
  • Better suited for batch processing

⚠️ Quality Concerns:

  • Optimization quality is average (user feedback: "GLM效果不好")
  • Consider alternatives like DeepSeek for better quality
  • Use GLM when cost is a priority over quality

⚠️ Token Consumption:

  • Higher token usage compared to alternatives
  • May not be cost-effective for large-scale applications

Best Practices

1. Use for Batch Processing

GLM-4.7 is best suited for non-interactive, background tasks:

// ✅ Good: Background batch processing
async function batchOptimizePrompts(prompts) {
  const results = [];
  for (const prompt of prompts) {
    const result = await glmClient.optimize(prompt);
    results.push(result);
  }
  return results;
}

// ❌ Bad: Real-time user interaction
async function handleUserChat(message) {
  // User waits 60+ seconds - poor UX
  const response = await glmClient.chat(message);
  return response;
}

2. Implement Retry Logic

Due to slower response times, implement retry logic:

async function callGLMWithRetry(request, maxRetries = 3) {
  for (let i = 0; i < maxRetries; i++) {
    try {
      const response = await axios.post(url, request, {
        timeout: 120000  // 2 minutes
      });
      return response.data;
    } catch (error) {
      if (i === maxRetries - 1) throw error;
      await new Promise(r => setTimeout(r, 5000 * (i + 1)));  // Exponential backoff
    }
  }
}

3. Fallback Strategy

Consider implementing fallback to alternative providers:

const PROVIDERS = {
  deepseek: { priority: 1, quality: 'high', speed: 'fast' },
  glm_coding: { priority: 2, quality: 'medium', speed: 'slow' }
};

async function optimizeWithFallback(prompt) {
  // Try DeepSeek first (faster, better quality)
  try {
    return await callDeepSeek(prompt);
  } catch (error) {
    console.warn('DeepSeek failed, falling back to GLM');
    return await callGLM(prompt);
  }
}

Comparison with Alternatives

FeatureGLM-4.7 CodingDeepSeek[ge2.5]
SpeedSlow (~60s)Fast (~10s)Fast (~15s)
QualityAverageGoodGood
CostLowerHigher-
Use CaseBatch tasksReal-timeReal-time
Response Format
reasoning_content
content
content

Troubleshooting

Problem: Empty response from GLM

Symptom: API returns success but

result
is empty string

Root Cause: Reading

message.content
instead of
message.reasoning_content

Solution:

// ❌ Wrong
const result = response.data.choices[0].message.content;

// ✅ Correct
const message = response.data.choices[0].message;
const result = message.content || message.reasoning_content || '';

Problem: Timeout errors

Symptom: Request timeout after 30 seconds

Root Cause: GLM-4.7 needs more time to process (reasoning step)

Solution: Increase timeout to 120 seconds

await axios.post(url, body, { timeout: 120000 });

Problem: 404 Not Found

Symptom: API returns 404 error

Root Cause: Using wrong endpoint format

Solution: Verify endpoint is

/chat/completions
without
/v1
prefix

// ✅ Correct
const url = 'https://open.bigmodel.cn/api/coding/paas/v4/chat/completions';

// ❌ Wrong
const url = 'https://open.bigmodel.cn/api/coding/paas/v4/v1/chat/completions';

References

See

references/glm_integration.md
for:

  • Complete API specification
  • Error handling patterns
  • Example implementations

Scripts

See

scripts/
for:

  • test_glm_connection.py
    - Test GLM API connectivity
  • benchmark_prompts.py
    - Benchmark prompt optimization