Download the PHP package thinwrap/llm without Composer
On this page you can find all versions of the php package thinwrap/llm. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package llm
Short Description Unified, SDK-free PHP facade over LLM chat & embeddings APIs — OpenAI, Anthropic, Bedrock, Gemini and 14 more behind one typed interface. Stateless, no vendor SDKs; BYO PSR-18 HTTP client, with php-http/discovery as the only runtime dependency (auto-wires a client when none is injected).
License MIT
Homepage https://thinwrap.dev
Informations about the package llm
thinwrap/llm
Unified, SDK-free PHP facade over LLM chat-completion & embeddings providers. One typed Chat facade; switch vendor by changing the provider id + model. Stateless, bring your own PSR-18 HTTP client, no vendor SDKs — the in-process, zero-egress complement to an LLM gateway.
Install
Requires PHP ≥8.2. A PSR-18 HTTP client + PSR-17 factories are auto-discovered via
php-http/discovery — if you don't already have one installed:
End-to-end example
Switching providers
Change the LlmProviderId case, the config class, and the model; the input and
output shape stay identical.
The 15 first-class OpenAI-compatible providers all take OpenAiCompatConfig:
openai, azure-openai, openrouter, groq, together, fireworks, deepseek,
xai, mistral, perplexity, deepinfra, cloudflare, vllm, ollama, lmstudio.
anthropic, bedrock, and gemini are native adapters.
Per-provider docs (auth, config, quirks, rate-limit links, error mapping) live in
src/Providers/ — one README per provider.
Streaming
stream() returns a \Generator<ChatStreamDelta>. It reads the provider's
text/event-stream response off the PSR-7 body incrementally. Bedrock (whose
stream uses AWS binary event-stream framing) falls back to a single Converse call
replayed as deltas.
Embeddings
Bring your own PSR-18 client
Inject any PSR-18 client (and, optionally, PSR-17 factories) as constructor
arguments — useful for tracing, retries, mocking, or proxying through
symfony/http-client.
Contract: a non-2xx must be RETURNED, not thrown. PSR-18 requires this and compliant
clients honour it, so each connector can map the status to a ProviderCode
(429 → RateLimited, 401 → AuthFailed, …) and read the vendor's message. For an LLM
caller that is the difference between backing off and treating a rate limit as an outage.
A client that raises instead — Guzzle used outside its PSR-18 adapter, or a decorator
calling raise-on-error — is handled defensively: the answered response is recovered from
the exception's getResponse() so classification still runs.
The wrapper holds no state — no cache, no connection pool, no retry buffer. For an
already-built connector (a custom provider, say), use Chat::fromConnector($connector).
_passthrough escape valve
When the normalized input doesn't expose a vendor-specific field, forward arbitrary
keys via _passthrough on the input DTO. The connector deep-merges body, and merges
headers / query; consumer values win on collision. Keys are forwarded verbatim.
Error handling
Every failure surfaces as ConnectorError with a typed ProviderCode
(rate_limited, auth_failed, provider_unavailable, invalid_request,
context_length_exceeded, content_filtered, unknown). There is no top-level
retryAfterSeconds field — the raw Retry-After and its parsed seconds ride in
$e->cause. The wrapper performs no automatic retry.
Security
Report vulnerabilities privately — please do not open a public issue. Preferred: a private security advisory on this repository. Alternatively, email [email protected]. Include the affected versions and a minimal reproduction if you have one.
A vulnerability in a provider's own API or service belongs to that vendor rather than to this wrapper — please report those upstream.
MIT © Dmitry Polyanovsky
All versions of llm with dependencies
psr/http-client Version ^1.0
psr/http-factory Version ^1.0
psr/http-message Version ^1.0 || ^2.0
php-http/discovery Version ^1.20