cayleygraph/cayley · error
request is too large
Error message
request is too large
What it means
readLimit caps any v1 write/delete request body at maxQuerySize (1 MiB). It reads via io.LimitReader; if the body fills (or exceeds) the limit, ioutil.ReadAll reports an error and lr.N <= 0 signals the reader was exhausted, so the function replaces it with "request is too large". The library enforces this to prevent unbounded memory use from large bulk writes.
Source
Thrown at internal/http/write.go:67
Subject: quad.StringToValue(jq.Subject),
Predicate: quad.StringToValue(jq.Predicate),
Object: quad.StringToValue(jq.Object),
Label: quad.StringToValue(jq.Label),
}
if !q.IsValid() {
return nil, fmt.Errorf("invalid quad at index %d. %s", i, q)
}
out = append(out, q)
}
return out, nil
}
const maxQuerySize = 1024 * 1024 // 1 MB
func readLimit(r io.Reader) ([]byte, error) {
lr := io.LimitReader(r, maxQuerySize).(*io.LimitedReader)
data, err := ioutil.ReadAll(lr)
if err != nil && lr.N <= 0 {
err = errors.New("request is too large")
}
return data, err
}
func (api *API) ServeV1Write(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
if api.config.ReadOnly {
jsonResponse(w, 400, "Database is read-only.")
return
}
// TODO: streaming reader
bodyBytes, err := readLimit(r.Body)
if err != nil {
jsonResponse(w, 400, err)
return
}
quads, err := ParseJSONToQuadList(bodyBytes)
if err != nil {
jsonResponse(w, 400, err)View on GitHub (pinned to 81dcd7d73e)
Solutions
- Split the payload into chunks smaller than 1 MB and issue multiple /api/v1/write (or /delete) requests.
- Use the dedicated bulk loader tool (cayley load) or the load endpoint for large datasets instead of the HTTP write API.
- Compress/deduplicate the data before sending to get under the cap.
- If you truly need bigger requests, fork/rebuild with a larger maxQuerySize (internal/http/write.go).
Example fix
// before
body := buildAllQuadsJSON() // 5 MB
http.Post(url, "application/json", strings.NewReader(body))
// after
for _, chunk := range chunkBytes(buildAllQuadsJSON(), 900*1024) {
http.Post(url, "application/json", bytes.NewReader(chunk))
} Defensive patterns
Strategy: validation
Validate before calling
const maxQuerySize = 1024 * 1024
if len(payload) >= maxQuerySize {
return errors.New("payload must be chunked under 1 MiB for /api/v1/write")
} Try / catch
resp, err := client.Post(writeURL, "application/json", bytes.NewReader(chunk))
if err != nil { return err }
if resp.StatusCode == http.StatusBadRequest {
b, _ := io.ReadAll(resp.Body)
if strings.Contains(string(b), "request is too large") {
return chunkAndRetry(chunk)
}
} Prevention
- Chunk all write/delete payloads well below 1 MiB (e.g. 900 KB) before POSTing.
- Use the bulk loader (cayley load) for large imports instead of the HTTP write API.
- Add a size assertion in your data-pipeline tests for generated request bodies.
When it happens
Trigger: POSTing to /api/v1/write or /api/v1/delete with a JSON body larger than 1024*1024 bytes (1 MB). Any payload whose size reaches the LimitReader cap triggers this regardless of content validity.
Common situations: Bulk-loading a large N-Quads/JSON set in a single request instead of chunking; migrating data from another store via one huge write call; scripts that concatenate many quads into one POST; proxy/gateway timeouts prompting clients to batch aggressively.
Understand the failure class
Background: payload too large / request exceeds maximum size: why libraries cap bytes and how to fix oversize payloads — this error's family across 50 libraries.
Related errors
- request is too large
- request data is too large
- no support for HTTP interface for this query language
- HTTP interface is not supported for this query language
- invalid quad at index %d. %s
AI-assisted analysis of cayleygraph/cayley@81dcd7d73e (2026-09-06).
Data as JSON: /api/errors/d950ea0560def8a4.
Report an issue: GitHub.