Skip to content

API Reference

Refringe edited this page Oct 28, 2026 · 20 revisions

API Reference

Anchor LFS implements the Git LFS Batch API and the File Locking API. This page documents all HTTP endpoints.

All LFS endpoints are registered per-endpoint at the configured path prefix. For an endpoint configured as endpoint = "/org/repo", the batch endpoint would be /org/repo/objects/batch.

Content Types

LFS API requests and responses use:

Content-Type: application/vnd.git-lfs+json
Accept: application/vnd.git-lfs+json

The Content-Type must be the LFS media type. The Accept header may list several types; it is accepted when any entry is the LFS media type, application/* or */*, and an entry with q=0 does not count. Lock requests check credentials before these headers, so a request without valid credentials gets 401 first.

Server Endpoints

Health Check

GET /health

Returns 200 with the server version whenever the process is running; use it as a liveness check. Not rate limited.

Response:

{
  "status": "ok",
  "version": "v0.2.0"
}

Readiness Check

GET /ready

Checks that the data directory accepts new files and that the storage backend is reachable (for S3, a HeadBucket request). Results are cached for 5 seconds. Not rate limited.

Response (200 OK):

{
  "status": "ready"
}

Response (503 Service Unavailable): failed names the check that failed, data_directory or storage. The cause is written to the server log, not the response.

{
  "status": "not ready",
  "failed": "storage"
}

Root

GET /

Returns version information. Not rate limited.

Response:

{
  "version": "v0.2.0"
}

Unknown Paths

Any request, whatever its method, to a path that is not one of the routes on this page returns 404 Not Found with a Git LFS error body (application/vnd.git-lfs+json):

{
  "message": "no Git LFS endpoint at this path",
  "request_id": "a1b2c3d4e5f60718",
  "documentation_url": "https://github.com/refringe/anchor-lfs/wiki"
}

This includes requests to a configured endpoint path with the wrong method. Git LFS clients report it as batch response: no Git LFS endpoint at this path, and treat a 404 from {prefix}/locks/verify as a server without locking support.

Batch API

Transfer Negotiation

POST {prefix}/objects/batch

Negotiate downloads or uploads for one or more objects. Rate limited.

Request:

{
  "operation": "download",
  "transfers": ["basic"],
  "hash_algo": "sha256",
  "ref": {
    "name": "refs/heads/main"
  },
  "objects": [
    {
      "oid": "abc123def456...",
      "size": 12345678
    }
  ]
}
Field Required Description
operation Yes "download" or "upload"
transfers No Transfer adapters the client supports. Only "basic" is supported.
hash_algo No Hash algorithm. Only "sha256" is supported; any other value gives every object a 409 error.
ref No Git ref for the request. Accepted for spec compliance but Anchor LFS authorises at repository level, not per-branch.
objects Yes Array of objects to download or upload. Maximum 1000 per request; more returns 413.

Response:

{
  "transfer": "basic",
  "objects": [
    {
      "oid": "abc123def456...",
      "size": 12345678,
      "authenticated": true,
      "actions": {
        "download": {
          "href": "https://lfs.example.com/org/repo/objects/abc123def456...?exp=1709990400&sig=base64sig",
          "expires_in": 600,
          "expires_at": "2026-03-09T12:00:00Z"
        }
      }
    }
  ],
  "hash_algo": "sha256"
}

Action types returned:

Action When Description
download Download operation, object exists URL to download the object
upload Upload operation, object doesn't exist URL to upload the object
verify Upload operation, object doesn't exist URL to verify the upload (called after upload)

With S3 storage and presigned URLs enabled, upload and download actions point directly at the bucket, and each upload action carries a header map (an x-amz-checksum-sha256 value) that the client must send with the upload. Git LFS clients do this automatically.

Error responses per object:

If an individual object has an error (e.g., not found during download, exceeds max size during upload, already stored with a different size than the one declared, or requested with an unsupported hash_algo), the response includes an error field instead of actions:

{
  "oid": "abc123...",
  "size": 12345678,
  "error": {
    "code": 404,
    "message": "object not found"
  }
}

Object Transfer

Download Object

GET {prefix}/objects/{oid}

Download an LFS object. Not rate limited. Requires a valid HMAC signature on the URL.

Features:

  • Range requests: Supports the Range header for resumable downloads (when using local storage)
  • ETags: Returns the OID as the ETag header; a request with a matching If-None-Match gets 304 Not Modified
  • Content-Type: application/octet-stream
  • Cache-Control: no-store, as on every JSON response, so caching proxies do not keep objects or signed URLs

URL Parameters:

Parameter Description
exp Expiration timestamp (Unix epoch)
sig Base64-encoded HMAC-SHA256 signature

Upload and verify URLs carry the same two parameters. Each URL is signed for its operation and host, so it is rejected with 403 when used for another operation, at another host, or with any other query parameter.

Upload Object

PUT {prefix}/objects/{oid}

Upload an LFS object. Not rate limited. Requires a valid HMAC signature on the URL.

Request Headers:

Header Required Description
Content-Length No Size of the upload in bytes. Without it, as with chunked transfer encoding, the body is read until it ends and is still limited to max_upload_size.
Content-Type No Ignored. The body is treated as opaque bytes, so any value (or none) is accepted.

Upload Process:

  1. The server streams the request body to storage
  2. SHA-256 hash is computed during the upload
  3. If the hash doesn't match the OID, the object is deleted and a 400 error is returned
  4. If the body ends early or the client disconnects, nothing is stored and a 400 error is returned
  5. On success, returns 200 OK

Verify Upload

POST {prefix}/objects/verify

Verify that an uploaded object was stored correctly. Not rate limited. Requires a valid HMAC signature on the URL.

Request:

{
  "oid": "abc123def456...",
  "size": 12345678
}

Response:

  • 200 OK: Object exists and size matches
  • 404 Not Found: Object not found
  • 422 Unprocessable Entity: Size mismatch

File Locking API

Create Lock

POST {prefix}/locks

Create a file lock. Rate limited.

Request:

{
  "path": "assets/model.bin",
  "ref": {
    "name": "refs/heads/main"
  }
}

Response (201 Created):

{
  "lock": {
    "id": "unique-lock-id",
    "path": "assets/model.bin",
    "locked_at": "2026-03-09T12:34:56Z",
    "owner": {
      "name": "username"
    }
  }
}

Error (409 Conflict): Returned if the file is already locked.

List Locks

GET {prefix}/locks

List file locks. Rate limited.

Query Parameters:

Parameter Description
path Filter by file path
id Filter by lock ID
cursor Pagination cursor from a previous response
limit Maximum number of locks to return (default: 100, max: 1000)
refspec Git ref (accepted for compatibility)

Response:

{
  "locks": [
    {
      "id": "unique-lock-id",
      "path": "assets/model.bin",
      "locked_at": "2026-03-09T12:34:56Z",
      "owner": {
        "name": "username"
      }
    }
  ],
  "next_cursor": ""
}

Verify Locks

POST {prefix}/locks/verify

List locks, separated into "ours" (owned by the authenticated user) and "theirs" (owned by others). Rate limited.

Request:

{
  "cursor": "",
  "limit": 100,
  "ref": {
    "name": "refs/heads/main"
  }
}

Response:

{
  "ours": [
    {
      "id": "lock-id-1",
      "path": "assets/our-file.bin",
      "locked_at": "2026-03-09T12:00:00Z",
      "owner": {
        "name": "our-username"
      }
    }
  ],
  "theirs": [
    {
      "id": "lock-id-2",
      "path": "assets/their-file.bin",
      "locked_at": "2026-03-09T11:00:00Z",
      "owner": {
        "name": "other-username"
      }
    }
  ],
  "next_cursor": ""
}

Unlock

POST {prefix}/locks/{id}/unlock

Release a file lock. Rate limited.

Request:

{
  "force": false
}

Set force to true to override lock ownership and unlock a file locked by another user. On a github endpoint this needs the maintain or admin permission on the repository; without it, unlocking another user's lock fails with 403.

Response (200 OK):

{
  "lock": {
    "id": "unique-lock-id",
    "path": "assets/model.bin",
    "locked_at": "2026-03-09T12:34:56Z",
    "owner": {
      "name": "username"
    }
  }
}

Common Response Headers

Header Description
X-Request-ID Request identifier, also logged as request_id on the server's log lines for the request. Sent on every response. A trusted proxy's own X-Request-ID is reused.
Content-Type application/vnd.git-lfs+json for LFS responses

HTTP Status Codes

Code Meaning
200 Success
201 Created (lock created)
400 Bad request (uploaded content does not match its SHA-256 OID, or the upload was interrupted)
401 Unauthorised (missing or invalid credentials)
403 Forbidden (insufficient permissions)
404 Not found (also a batch download whose credentials cannot read the repository)
406 Not acceptable (the Accept header does not allow application/vnd.git-lfs+json)
408 Request timeout (an upload sent no data for upload_idle_timeout)
409 Conflict (lock already exists)
413 Payload too large (an upload over max_upload_size, a JSON body over 1 MB, or a batch request with more than 1000 objects)
415 Unsupported media type (the Content-Type header is not application/vnd.git-lfs+json)
422 Unprocessable entity (request body is not valid JSON or has invalid values, such as a malformed OID, operation, lock path, limit or lock cursor; size mismatch on verify)
429 Too many requests (rate limit exceeded, or GitHub rate limiting the token; includes Retry-After header)
500 Internal server error
502 Bad gateway (the GitHub API could not be reached to authenticate the request)
507 Insufficient storage (disk full)

Request Limits

Limit Value
Maximum objects per batch request 1000
Maximum JSON request body 1 MB
Maximum upload size Configurable (default: 5 GiB)

Next Steps

Clone this wiki locally

⌂ 换网址