Step-by-step tutorials to integrate MiniMax into your workflow
Add AI code generation to your OpenClaw agent workflows
OpenClaw is an AI assistant framework. Integrate MiniMax to give your agents code-writing capabilities.
pip install minimax-code
# tools/minimax_code.py
from minimax_code import MiniMaxCode
import os
class MiniMaxCodeTool:
def __init__(self):
self.client = MiniMaxCode(api_key=os.getenv("MINIMAX_API_KEY"))
def generate_code(self, prompt: str, language: str = "python") -> str:
"""Generate code from a text prompt."""
result = self.client.complete(
code=prompt,
language=language
)
return result.suggestion
def review_code(self, code: str) -> dict:
"""Review code for bugs and issues."""
result = self.client.review(code=code, language="python")
return result.issues
# Register as OpenClaw tool
tool = MiniMaxCodeTool()
# openclaw.yaml
tools:
- name: minimax_code
enabled: true
config:
api_key: ${MINIMAX_API_KEY}
default_language: python
max_tokens: 2048
# Use in your agent prompts
prompt: |
You have access to the MiniMax Code tool.
When user asks to write code, use the minimax_code.generate_code function.
# Add to your .env file
MINIMAX_API_KEY=your_api_key_here
💡 Pro Tip: Add code generation to any OpenClaw workflow by calling the MiniMax API in your tool definitions.
Build a custom VS Code extension with MiniMax
npm init -y
npm install vscode @types/vscode axios
// extension.ts
import * as vscode from 'vscode';
import axios from 'axios';
const API_KEY = process.env.MINIMAX_API_KEY;
export function activate(context: vscode.ExtensionContext) {
// Register AI Code Completion command
const completeCommand = vscode.commands.registerCommand(
'minimax.complete',
async () => {
const editor = vscode.window.activeTextEditor;
if (!editor) return;
const document = editor.document;
const position = editor.selection.active;
const text = document.getText();
// Get current line context
const line = document.lineAt(position.line).text;
const response = await axios.post(
'https://api.minimax.io/v1/code/complete',
{
code: line,
language: getLanguageId(document.languageId)
},
{ headers: { Authorization: \`Bearer \${API_KEY}\` }}
);
if (response.data.suggestion) {
await editor.edit(insertBuilder => {
insertBuilder.insert(position, response.data.suggestion);
});
}
}
);
context.subscriptions.push(completeCommand);
}
function getLanguageId(lang: string): string {
const map: Record = {
'python': 'python',
'javascript': 'javascript',
'typescript': 'typescript',
'go': 'go',
'rust': 'rust'
};
return map[lang] || 'python';
}
// keybindings.json
[
{
"key": "ctrl+shift+a",
"command": "minimax.complete",
"when": "editorTextFocus"
}
]
vsce package
code --install-extension minimax-ai-1.0.0.vsix
Add AI code review to your CI/CD pipeline
# .github/workflows/ai-code-review.yml
name: AI Code Review
on:
pull_request:
branches: [main, develop]
jobs:
ai-review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install MiniMax SDK
run: pip install minimax-code github-sdk
- name: Run AI Code Review
env:
MINIMAX_API_KEY: ${{ secrets.MINIMAX_API_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
python << 'EOF'
import os
import github
from minimax_code import MiniMaxCode
client = MiniMaxCode(api_key=os.getenv("MINIMAX_API_KEY"))
gh = github.Github(os.getenv("GITHUB_TOKEN"))
# Get PR diff
pr = gh.get_pull(...)
for file in pr.get_files():
# Analyze each changed file
issues = client.review(
code=file.patch,
language=detect_language(file.filename)
)
if issues:
pr.create_review_comment(
body=f"🤖 AI Review: {issues}",
commit_id=file.commit_id,
path=file.filename
)
EOF
MINIMAX_API_KEYAdd automated code review to Jenkins pipelines
// Jenkinsfile
pipeline {
agent any
environment {
MINIMAX_API_KEY = credentials('minimax-api-key')
}
stages {
stage('AI Code Scan') {
steps {
sh '''
pip install minimax-code
python3 << 'PYEOF'
import os
import glob
from minimax_code import MiniMaxCode
client = MiniMaxCode(api_key=os.environ["MINIMAX_API_KEY"])
# Scan all Python files
for file in glob.glob("**/*.py"):
with open(file) as f:
code = f.read()
issues = client.review(code=code, language="python")
if issues:
print(f"⚠️ {file}: {len(issues)} issues found")
for issue in issues:
print(f" - {issue}")
PYEOF
'''
}
}
}
post {
always {
cleanWs()
}
}
}
Complete Python SDK documentation
pip install minimax-code
from minimax_code import MiniMaxCode
client = MiniMaxCode(api_key="YOUR_API_KEY")
# Complete partial code
result = client.complete(
code="def fibonacci(n):",
language="python"
)
print(result.suggestion)
# Output:
# if n <= 1:
# return n
# return fibonacci(n-1) + fibonacci(n-2)
# Generate code from description
result = client.generate(
prompt="Create a function that validates email addresses using regex",
language="python"
)
print(result.code)
# Find bugs in code
code = """
def divide(a, b):
return a / b
"""
result = client.review(code=code, language="python")
for issue in result.issues:
print(f"Line {issue.line}: {issue.type} - {issue.message}")
# Output: Line 2: Warning - Potential division by zero
# Auto-generate tests
result = client.generate_tests(
code=existing_code,
language="python",
framework="pytest"
)
print(result.tests)
Complete JavaScript/TypeScript SDK
npm install minimax-code
const { MiniMaxCode } = require('minimax-code');
const client = new MiniMaxCode({
apiKey: process.env.MINIMAX_API_KEY
});
// Code completion
const completion = await client.complete({
code: 'const fibonacci = (n) => {',
language: 'javascript'
});
console.log(completion.suggestion);
// Code review
const review = await client.review({
code: `function add(a, b) { return a + b; }`,
language: 'javascript'
});
console.log(review.issues);
import { MiniMaxCode } from 'minimax-code';
const client = new MiniMaxCode({
apiKey: process.env.MINIMAX_API_KEY
});
// Full TypeScript support
const result = await client.complete({
code: 'const processData = (data: string[]): number => {',
language: 'typescript'
});
Use MiniMax from the command line
pip install minimax-code-cli
# Or via npm
npm install -g minimax-cli
# Complete code
minimax complete "def hello_world():" --lang python
# Review code file
minimax review app.py
# Generate from prompt
minimax generate "create a REST API endpoint" --lang python
# Explain code
minimax explain app.py
# ~/.bashrc or ~/.zshrc
alias ai="minimax"
# Usage
ai complete "function add("
Trigger AI code review from any webhook
# webhook_server.py
from flask import Flask, request, jsonify
from minimax_code import MiniMaxCode
app = Flask(__name__)
client = MiniMaxCode(api_key="YOUR_API_KEY")
@app.route('/webhook/code-review', methods=['POST'])
def code_review():
data = request.json
code = data.get('code')
language = data.get('language', 'python')
result = client.review(code=code, language=language)
return jsonify({
'issues': result.issues,
'suggestions': result.suggestions
})
@app.route('/webhook/generate', methods=['POST'])
def generate_code():
data = request.json
prompt = data.get('prompt')
language = data.get('language', 'python')
result = client.generate(prompt=prompt, language=language)
return jsonify({
'code': result.code
})
if __name__ == '__main__':
app.run(port=5000)
# In your GitHub repo settings:
# Webhook URL: https://your-server.com/webhook/code-review
# Payload would be:
{
"code": "def calculate(): pass",
"language": "python"
}