Developer builds custom Prism provider to route Laravel LLM calls through Claude CLI
A developer working on a Laravel application that relies heavily on large language models built a custom provider to route AI calls through the Claude Code CLI instead of paid APIs. The motivation was cost savings: the developer already paid for a Claude Code subscription but was also accumulating separate API bills for LLM features like PDF extraction, summarization, and spell-checking. The solution exploits the fact that the Claude CLI accepts standard input and returns structured JSON output, making it behave similarly to a conventional API. A single PHP class extending Prism's Provider interface was written to shell out to the Claude binary, pass prompts via stdin, and parse the JSON response back into Prism-compatible objects. The approach covers text and structured response methods, deliberately omitting streaming and image support since those features are not used in the application.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in