{
    "openapi": "3.1.0",
    "info": {
        "title": "MixCache.com API",
        "version": "1.0.0",
        "description": "Search the MixCache.com catalog and buy the full text of books published by MixCache.com itself, delivered as plain Markdown text, for internal use only (no publishing or redistribution). Books by third-party authors and publishers and Extended Catalog books are not available. $49.95 per book. Get an API key at https://mixcache.com/users/api. Reference: https://mixcache.com/developers. Terms: https://mixcache.com/developers/terms.",
        "termsOfService": "https://mixcache.com/developers/terms"
    },
    "servers": [
        {
            "url": "https://mixcache.com/v1"
        }
    ],
    "security": [
        {
            "bearerAuth": []
        },
        {
            "apiKeyHeader": []
        }
    ],
    "paths": {
        "/search": {
            "get": {
                "summary": "Search eligible books (free, rate-limited)",
                "parameters": [
                    {
                        "name": "q",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "maxLength": 200
                        }
                    },
                    {
                        "name": "page",
                        "in": "query",
                        "schema": {
                            "type": "integer",
                            "minimum": 1,
                            "default": 1
                        }
                    },
                    {
                        "name": "per_page",
                        "in": "query",
                        "schema": {
                            "type": "integer",
                            "minimum": 1,
                            "maximum": 50,
                            "default": 20
                        }
                    },
                    {
                        "name": "language",
                        "in": "query",
                        "schema": {
                            "type": "string",
                            "enum": [
                                "en",
                                "es",
                                "fr",
                                "it",
                                "de",
                                "pt",
                                "nl",
                                "zh"
                            ]
                        },
                        "description": "\"en\" also matches books whose language is not yet detected"
                    },
                    {
                        "name": "book_type",
                        "in": "query",
                        "schema": {
                            "type": "string",
                            "enum": [
                                "fiction",
                                "nonfiction"
                            ]
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Results",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "query": {
                                            "type": "string"
                                        },
                                        "page": {
                                            "type": "integer"
                                        },
                                        "per_page": {
                                            "type": "integer"
                                        },
                                        "total": {
                                            "type": "integer"
                                        },
                                        "results": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/BookSummary"
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Invalid parameters",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "Missing or invalid API key",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "429": {
                        "description": "Rate limited",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/books/{id}": {
            "get": {
                "summary": "Book detail with table of contents and a free sample of the first 3 sections",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Book detail",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "allOf": [
                                        {
                                            "$ref": "#/components/schemas/BookSummary"
                                        },
                                        {
                                            "type": "object",
                                            "properties": {
                                                "description": {
                                                    "type": "string"
                                                },
                                                "bullet_points": {
                                                    "type": "array",
                                                    "items": {
                                                        "type": "string"
                                                    }
                                                },
                                                "target_audience": {
                                                    "type": "string"
                                                },
                                                "categories": {
                                                    "type": "array",
                                                    "items": {
                                                        "type": "string"
                                                    }
                                                },
                                                "table_of_contents": {
                                                    "type": "string"
                                                },
                                                "sections_total": {
                                                    "type": "integer"
                                                },
                                                "sample": {
                                                    "type": "array",
                                                    "items": {
                                                        "$ref": "#/components/schemas/Section"
                                                    }
                                                },
                                                "owned": {
                                                    "type": "boolean"
                                                }
                                            }
                                        }
                                    ]
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Not an available book",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/books/{id}/text": {
            "get": {
                "summary": "Full text of a purchased book (plain Markdown, or JSON sections with format=json)",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "format",
                        "in": "query",
                        "schema": {
                            "type": "string",
                            "enum": [
                                "json"
                            ]
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "The book",
                        "content": {
                            "text/markdown": {
                                "schema": {
                                    "type": "string"
                                }
                            },
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "id": {
                                            "type": "integer"
                                        },
                                        "title": {
                                            "type": "string"
                                        },
                                        "sections": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/Section"
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Not purchased by this account (not_owned)",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/purchase": {
            "post": {
                "summary": "Buy books: one charge to the card saved on the account. Use ?dry_run=1 for a quote.",
                "parameters": [
                    {
                        "name": "dry_run",
                        "in": "query",
                        "schema": {
                            "type": "string",
                            "enum": [
                                "1"
                            ]
                        }
                    },
                    {
                        "name": "Idempotency-Key",
                        "in": "header",
                        "required": false,
                        "schema": {
                            "type": "string",
                            "maxLength": 255
                        },
                        "description": "Required for real purchases. Reuse only to retry the same purchase; it never charges twice."
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "required": [
                                    "books"
                                ],
                                "properties": {
                                    "books": {
                                        "type": "array",
                                        "maxItems": 1000,
                                        "items": {
                                            "oneOf": [
                                                {
                                                    "type": "integer",
                                                    "description": "A book id"
                                                },
                                                {
                                                    "type": "string",
                                                    "pattern": "^\\d+-\\d+$",
                                                    "description": "Inclusive id range; only available books inside it are included"
                                                }
                                            ]
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "Purchase result, or the quote for a dry run",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Invalid request, ineligible_books, too_many_books (max 100), idempotency_key_required",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "402": {
                        "description": "no_payment_method, card_declined, card_requires_authentication, daily_cap_exceeded",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "purchase_in_progress",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "502": {
                        "description": "payment_error: retry with the same Idempotency-Key",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/library": {
            "get": {
                "summary": "Books this account has bought, newest first",
                "parameters": [
                    {
                        "name": "page",
                        "in": "query",
                        "schema": {
                            "type": "integer",
                            "minimum": 1
                        }
                    },
                    {
                        "name": "per_page",
                        "in": "query",
                        "schema": {
                            "type": "integer",
                            "minimum": 1,
                            "maximum": 200
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Owned books",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object"
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {
        "securitySchemes": {
            "bearerAuth": {
                "type": "http",
                "scheme": "bearer"
            },
            "apiKeyHeader": {
                "type": "apiKey",
                "in": "header",
                "name": "X-API-Key"
            }
        },
        "schemas": {
            "BookSummary": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": "integer"
                    },
                    "title": {
                        "type": "string"
                    },
                    "subtitle": {
                        "type": [
                            "string",
                            "null"
                        ]
                    },
                    "author": {
                        "type": "string"
                    },
                    "book_type": {
                        "type": "string",
                        "enum": [
                            "fiction",
                            "nonfiction"
                        ]
                    },
                    "language": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "ISO 639-1 code; null if not yet detected"
                    },
                    "words": {
                        "type": [
                            "integer",
                            "null"
                        ]
                    },
                    "published_at": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "format": "date-time"
                    },
                    "price": {
                        "type": "number"
                    },
                    "currency": {
                        "type": "string"
                    },
                    "cover_url": {
                        "type": [
                            "string",
                            "null"
                        ]
                    },
                    "url": {
                        "type": "string"
                    }
                }
            },
            "Section": {
                "type": "object",
                "properties": {
                    "heading": {
                        "type": "string"
                    },
                    "text": {
                        "type": "string"
                    }
                }
            },
            "Error": {
                "type": "object",
                "properties": {
                    "error": {
                        "type": "object",
                        "properties": {
                            "code": {
                                "type": "string"
                            },
                            "message": {
                                "type": "string"
                            }
                        }
                    }
                }
            }
        }
    }
}