Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docsa.stemfard.com/llms.txt

Use this file to discover all available pages before exploring further.

When a request to the Stemfard API cannot be completed successfully, the API returns a non-200 HTTP status code and a JSON response body that describes what went wrong. Your application should always check the HTTP status code before processing a response, and handle error responses appropriately rather than assuming every response contains valid result data.

HTTP status codes

StatusNameWhen it occurs
200OKThe request succeeded. The response body contains the computed result.
401UnauthorizedThe Authorization header is missing, malformed, or contains an invalid API key.
422Unprocessable EntityThe request body failed validation — a required field is missing, a value is the wrong type, or a parameter value is not in the allowed set.
500Internal Server ErrorAn unexpected error occurred on the server. If this persists, contact support.

Validation error response (422)

When the API returns 422, the response body follows this schema:
{
  "detail": [
    {
      "loc": ["body", "a"],
      "msg": "field required",
      "type": "value_error.missing"
    }
  ]
}
The detail array contains one entry for each validation problem found in your request.
detail
object[]
required
Array of validation error objects. Contains one entry per field that failed validation.

Common validation errors

Error typeCauseFix
value_error.missingA required field is absent from the request bodyAdd the missing field (commonly a or b)
type_error.listA matrix field was not sent as a 2D arrayEnsure a and b are arrays of arrays of numbers
value_error.constAn enum field received an unrecognised valueCheck the allowed values for operation or type
type_error.integerA numeric field received a non-integer valueCheck the type of decimals and similar fields

Handling errors

The examples below show how to detect and handle error responses in your application.
# Check the HTTP status code with -w and -o
curl --request POST \
  --url https://api.stemfard.com/api/v1/mathematics/linear-algebra/matrix-operations/matrix-arithmetic/add \
  --header 'Authorization: Bearer <your-api-key>' \
  --header 'Content-Type: application/json' \
  --data '{"b": [[1,2],[3,4]]}' \
  --silent \
  --output response.json \
  --write-out '%{http_code}'

# Non-200 output: 422
# response.json will contain the validation error detail

Example error responses

401 — missing API key
{
  "detail": "Not authenticated"
}
422 — missing required field
{
  "detail": [
    {
      "loc": ["body", "a"],
      "msg": "field required",
      "type": "value_error.missing"
    }
  ]
}
422 — multiple validation failures
{
  "detail": [
    {
      "loc": ["body", "a"],
      "msg": "field required",
      "type": "value_error.missing"
    },
    {
      "loc": ["body", "operation"],
      "msg": "value is not a valid enumeration member; permitted: 'all', 'add', 'subtract', 'multiply-ew', 'divide-ew', 'raise-ew', 'matmul'",
      "type": "type_error.enum"
    }
  ]
}
Do not retry requests that return 422. A validation error means your request body is malformed — retrying the same request will always produce the same error. Fix the request body first, then retry.