openai-php/client
PHP语言的OpenAI API客户端库,支持连接OpenAI及兼容/v1端点的第三方LLM服务
时间轴 (近 90 天)
openai-php/client 和 openai-php/laravel 可以连接 vLLM、LiteLLM、Ollama 的 /v1 端点或任何托管网关。
openai-php/client 在调用方未显式传入 HTTP 客户端时,会尝试通过 PSR-18 实现发现可用的客户端。
openai-php/client 对 base URI 只做末尾补 / 和缺少协议时补 https:// 的清理,然后拼接相对路径;末尾带斜杠会导致请求路径出现双斜杠并返回 404。
使用 openai-php/client 时,如果 base URI 未写全 http://,本地纯 HTTP 服务会因 TLS 报错,出现 cURL error 35: wrong version number。
openai-php/client 的 factory 通过 PSR-18 发现机制找到 Guzzle 时,默认不设置任何超时。
openai-php/client 将 HTTP 429 映射为 RateLimitException,原始响应可通过 $e->response 获取,并能读取 Retry-After 头。
openai-php/client 将 5xx 映射为 ServerException,其他带 JSON 错误体的 4xx 映射为 ErrorException,网络故障和超时映射为 TransporterException。
openai-php/client 的 ErrorException 的 getErrorCode() 返回服务端 code 字段的字符串,判断时应比较 HTTP 状态码而非该值。
openai-php/client 库本身不内置重试机制,重试应只针对 RateLimitException、ServerException、TransporterException,且优先遵守 Retry-After 头。
openai-php/client 的 createStreamed() 会自动设置 stream: true;开启 include_usage 后最后一个 chunk 的 choices 是空数组,读取前必须用 isset 判断。
还有 1 条时间轴事件
全部知识事实 (12)
openai-php/client 由 Nuno Maduro 等 PHP 社区知名开发者发起并持续维护
90%待验证openai-php/client 和 openai-php/laravel 可以连接 vLLM、LiteLLM、Ollama 的 /v1 端点或任何托管网关。
50%待验证openai-php/client 在调用方未显式传入 HTTP 客户端时,会尝试通过 PSR-18 实现发现可用的客户端。
50%待验证openai-php/client 对 base URI 只做末尾补 / 和缺少协议时补 https:// 的清理,然后拼接相对路径;末尾带斜杠会导致请求路径出现双斜杠并返回 404。
50%待验证使用 openai-php/client 时,如果 base URI 未写全 http://,本地纯 HTTP 服务会因 TLS 报错,出现 cURL error 35: wrong version number。
50%待验证openai-php/client 的 factory 通过 PSR-18 发现机制找到 Guzzle 时,默认不设置任何超时。
50%待验证openai-php/client 将 HTTP 429 映射为 RateLimitException,原始响应可通过 $e->response 获取,并能读取 Retry-After 头。
50%待验证openai-php/client 将 5xx 映射为 ServerException,其他带 JSON 错误体的 4xx 映射为 ErrorException,网络故障和超时映射为 TransporterException。
50%待验证openai-php/client 的 ErrorException 的 getErrorCode() 返回服务端 code 字段的字符串,判断时应比较 HTTP 状态码而非该值。
50%待验证openai-php/client 库本身不内置重试机制,重试应只针对 RateLimitException、ServerException、TransporterException,且优先遵守 Retry-After 头。
50%待验证openai-php/client 的 createStreamed() 会自动设置 stream: true;开启 include_usage 后最后一个 chunk 的 choices 是空数组,读取前必须用 isset 判断。
50%待验证openai-php/client 使用 Guzzle 的 stream 选项发起流式请求,Guzzle 7 和 8 的 timeout 均无法拦截一个耗时超过 timeout 值的流。
50%