API Documentation

Integrate OpenCodeHub into your workflow with our comprehensive REST API

Quick Start

1. Get API Token

Generate a personal access token from your settings:

  1. Go to Settings → Tokens
  2. Click "Generate New Token"
  3. Select scopes: repo, pr
  4. Copy and save your token securely

2. API Base URL

All API requests should be made to:

https://git.yourcompany.com/api

Replace git.yourcompany.com with your instance URL

Quick Examples

Create Repository

POST /api/repos
curl -X POST https://git.yourcompany.com/api/repos \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "my-project",
    "description": "My awesome project",
    "visibility": "private"
  }'

List Pull Requests

GET /api/repos/:owner/:repo/pulls
curl https://git.yourcompany.com/api/repos/owner/repo/pulls \
  -H "Authorization: Bearer YOUR_TOKEN"

Create Pull Request

POST /api/repos/:owner/:repo/pulls
curl -X POST https://git.yourcompany.com/api/repos/owner/repo/pulls \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Add new feature",
    "head": "feature-branch",
    "base": "main",
    "body": "This PR adds..."
  }'

Rate Limiting

Authenticated Requests

5,000

requests per hour

Unauthenticated Requests

60

requests per hour

Check Limits

Response headers:

X-RateLimit-Remaining

Response Format

Success Response

{
  "data": {
    "id": "repo-123",
    "name": "my-project",
    "owner": {
      "username": "swadhin",
      "id": "user-456"
    },
    "visibility": "private",
    "created_at": "2024-01-01T12:00:00Z"
  },
  "meta": {
    "timestamp": "2024-01-01T12:00:01Z"
  }
}

Error Response

{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Repository name is required",
    "details": {
      "field": "name",
      "constraint": "required"
    }
  },
  "meta": {
    "timestamp": "2024-01-01T12:00:01Z",
    "request_id": "req-abc123"
  }
}

SDKs & Libraries

JavaScript/TypeScript

npm install @opencodehub/sdk
View docs →

Python

pip install opencodehub
View docs →

Go

go get github.com/opencodehub/sdk-go
View docs →

Additional Resources