Integration details for GitLab API and AI provider APIs.
Method: Personal Access Token
Headers:
PRIVATE-TOKEN: glpat-xxxxxxxxxxxxToken Scopes Required: api (Full API access)
Endpoint: GET /api/v4/issues
Purpose: Fetch list of issues from all accessible projects
Parameters:
state:opened(default)scope:all(optional)labels: Comma-separated label names (optional)order_by:created_atsort:descper_page:20(max 100)created_after: ISO 8601 timestamp
Example:
GET /api/v4/issues?scope=all&state=opened&labels=UNIOSS+3&order_by=created_at&sort=desc&per_page=20
Headers:
PRIVATE-TOKEN: glpat-xxxxxxxxxxxxEndpoint: GET /api/v4/projects/{project_id}/issues/{issue_iid}
Purpose: Fetch detailed issue information
Example:
GET /api/v4/projects/31/issues/366
Headers:
PRIVATE-TOKEN: glpat-xxxxxxxxxxxxEndpoint: GET /api/v4/projects/{project_id}/issues/{issue_iid}/notes
Purpose: Fetch all comments/notes for an issue
Endpoint: GET /api/v4/projects/{project_id}/issues/{issue_iid}/links
Purpose: Fetch related/linked issues
Event Type: Issue Hook
Setup:
- GitLab β Project β Settings β Webhooks
- URL:
https://your-app.com/webhook - Secret token: Your webhook secret
- Trigger: "Issue events"
- Enable SSL verification (recommended)
- GitLab.com: 2000 requests/hour per user
- Self-hosted: Depends on instance configuration
Handling: Implement request throttling, cache responses when possible, use webhooks instead of polling when available.
- OpenRouter (Recommended): Access to multiple models including DeepSeek with reasoning mode
- OpenAI: ChatGPT models (gpt-4, gpt-3.5-turbo, etc.)
Base URL: https://openrouter.ai/api/v1
Authentication: API Key in Authorization: Bearer header
Models: tngtech/deepseek-r1t2-chimera:free (default), deepseek/deepseek-v3.2, etc.
Reasoning Mode: Enabled by default when AI_ENABLE_REASONING=true
Request Format:
{
"model": "tngtech/deepseek-r1t2-chimera:free",
"messages": [
{"role": "system", "content": "..."},
{"role": "user", "content": "..."}
],
"temperature": 0.7,
"max_tokens": 16000,
"reasoning": {
"enabled": true
}
}Base URL: https://api.openai.com/v1
Authentication: API Key in Authorization: Bearer header
Models: gpt-4, gpt-4-turbo, gpt-3.5-turbo
Request Format:
{
"model": "gpt-4",
"messages": [
{"role": "system", "content": "..."},
{"role": "user", "content": "..."}
],
"temperature": 0.7,
"max_tokens": 2000
}Endpoint: POST {base_url}/chat/completions (OpenAI-compatible)
The system sends comprehensive issue data including:
- Issue title, description, metadata
- All comments with authors and timestamps
- Related issues (linked, blocking, blocked by)
- Attachments and images (URLs)
- Additional context
The AI analyzes this data using the WWWH-TR framework and returns structured analysis.
Common Errors:
- 401 Unauthorized: Invalid API key
- 429 Too Many Requests: Rate limit exceeded
- 500/503: Server errors
Retry Strategy: Exponential backoff (3 attempts: 1s, 2s, 4s)
Provider-Specific:
- OpenRouter: Varies by model (check current limits)
- OpenAI: Varies by tier (free tier: 3 requests/minute, paid: higher)
Handling: Implement exponential backoff, queue requests if needed, monitor usage per provider.
Provider Pricing (check current pricing):
- OpenRouter: Varies by model (DeepSeek models generally lower cost)
- OpenAI: Higher cost, excellent quality
Optimization:
- Monitor
usage.total_tokensin responses - Adjust
max_tokensbased on needs - Choose provider based on cost/quality trade-off
The system fetches comprehensive issue data including:
- Basic issue information (title, description, labels, etc.)
- All comments and notes (with author and timestamps)
- Related/linked issues (blocking, blocked by, duplicates, relates to)
- Attachments and images (extracted from description and comments)
- Issue relationships (epics, parent/child issues)
- Get basic issue info
- Get all comments
- Get related issues
- Extract attachments from description and comments
- Combine all data for AI analysis
- Include: All user comments (exclude system notes)
- Format: Author, timestamp, and content
- Purpose: Understand discussion context, solutions proposed, status updates
- Types: Blocking, blocked by, duplicates, relates to, closes
- Purpose: Understand issue dependencies and relationships
- Extraction: Parse markdown links from description and comments
- Types: Images, files, screenshots
- Purpose: Reference visual information in analysis
- Note: URLs are included in prompt; actual file content not downloaded (to save tokens)
- 401 Unauthorized: Invalid or expired token β Verify token and regenerate
- 404 Not Found: Invalid project ID β Verify project ID/path
- 429 Too Many Requests: Rate limit exceeded β Implement backoff, reduce polling frequency
- 500 Internal Server Error: GitLab server issue β Retry with exponential backoff
- 401 Unauthorized: Invalid API key β Verify API key for selected provider
- 429 Too Many Requests: Rate limit exceeded β Implement backoff, reduce request frequency
- 500/503: Server errors β Retry with exponential backoff, consider fallback provider
def retry_with_backoff(func, max_retries=3, backoff_factor=2.0, initial_delay=1.0):
"""Retry function with exponential backoff"""
delay = initial_delay
for attempt in range(max_retries):
try:
return func()
except requests.HTTPError as e:
if e.response.status_code in [429, 500, 503]:
if attempt < max_retries - 1:
time.sleep(delay)
delay *= backoff_factor
continue
raise
raise Exception("Max retries exceeded")- Error Handling: Always handle API errors gracefully
- Rate Limiting: Implement rate limiting to avoid hitting limits
- Retries: Use exponential backoff for retries
- Logging: Log all API calls and errors
- Timeouts: Set appropriate timeouts for API calls (default: 30 seconds)
- Validation: Validate API responses before processing
- Caching: Cache responses when appropriate (analysis cache for processed issues)
- Monitoring: Monitor API usage and costs
- Configure GitLab API token
- Configure AI provider API key
- Test API connectivity
- Monitor API usage and costs
- Set up error alerts