Replies: 1 comment
|
I really do like the idea of developing some generic contracts for PHP to use any model with streaming, tools, errors, and so on. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Motivation
LLM calls fit the PHP worker model poorly. A single call waits seconds to minutes on network I/O, streams tokens, keeps billing after the client disconnects, and is limited by tokens rather than requests. With one request per worker, 32 workers means 32 concurrent generations, each worker blocked on an upstream socket.
Rapira owns both the network layer and the workers, so it can take this I/O off PHP.
1. Worker I/O offload
PHP describes the call, Rapira executes it, and the worker is released:
Client disconnect aborts the upstream request.
2. Unified API (core)
One provider-agnostic API: messages, multimodal input, tool calling, structured output, a streaming event model, normalized errors and usage. It is exposed as a typed PHP package (transport goes through Rapira) and, optionally, as an OpenAI-compatible endpoint.
Provider-specific features (prompt caching, reasoning blocks, citations) are carried as typed extensions rather than dropped to a lowest common denominator.
3. Routing and fallbacks
fast,smart) map to an ordered list of provider/model pairs.Fallback is transparent only until the first token reaches the client. After that, the policy has to be explicit.
Future: streaming to WebSocket connections
Once Rapira supports WebSockets, the stream target can be decoupled from the initiating request. A worker starts a generation and targets an existing WS connection or channel instead of the HTTP response. Rapira pushes the token events there without any worker involvement.
Prior art
OpenRouter, LiteLLM and Portkey are gateways; symfony/ai and prism-php/prism are PHP abstractions. None of them combines the gateway with a server that owns the workers, which is what makes offload and cancellation possible.
Open questions
All reactions