{"id":29669336,"url":"https://github.com/chubes4/ai-http-client","last_synced_at":"2026-06-15T04:33:24.507Z","repository":{"id":304774756,"uuid":"1019906851","full_name":"chubes4/ai-http-client","owner":"chubes4","description":"Archived: superseded by WordPress wp-ai-client APIs.","archived":true,"fork":false,"pushed_at":"2026-04-30T17:47:47.000Z","size":4149,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-15T04:33:19.663Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chubes4.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-07-15T04:09:55.000Z","updated_at":"2026-04-30T17:53:09.000Z","dependencies_parsed_at":"2025-08-20T20:33:44.750Z","dependency_job_id":"927bd363-4235-41da-bd4f-86745fce94a5","html_url":"https://github.com/chubes4/ai-http-client","commit_stats":null,"previous_names":["chubes4/ai-http-client"],"tags_count":25,"template":false,"template_full_name":null,"purl":"pkg:github/chubes4/ai-http-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chubes4%2Fai-http-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chubes4%2Fai-http-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chubes4%2Fai-http-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chubes4%2Fai-http-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chubes4","download_url":"https://codeload.github.com/chubes4/ai-http-client/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chubes4%2Fai-http-client/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34348291,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-15T02:00:07.085Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-07-22T18:30:55.724Z","updated_at":"2026-06-15T04:33:24.494Z","avatar_url":"https://github.com/chubes4.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AI HTTP Client for WordPress\n\n\u003e **Archived:** This package is superseded by WordPress core's `wp-ai-client`\n\u003e APIs. Data Machine no longer uses this runtime dependency; provider/model/key\n\u003e administration and image generation have moved to `wp-ai-client`-shaped\n\u003e capabilities. This repository remains available for historical reference only\n\u003e and should not be used for new work.\n\nA professional WordPress library for unified AI provider communication. Supports OpenAI, Anthropic, Google Gemini, Grok, and OpenRouter with standardized request/response formats.\n\n**Key Features:**\n- WordPress filter-based architecture with self-contained provider classes\n- Unified request/response format across all AI providers\n- Comprehensive caching system with 24-hour model cache TTL\n- Multi-modal support (text, images, files) via native Files API integration\n- Streaming and standard request modes with proper error handling\n- REST API endpoints for configuration and management\n- Multisite network-wide API key storage support\n- Comprehensive error handling with WordPress action hooks\n\n## Installation\n\n**Composer** (recommended for standalone use):\n```bash\ncomposer require chubes4/ai-http-client\n```\n\n**Git Subtree** (recommended for plugin embedding):\n```bash\ngit subtree add --prefix=lib/ai-http-client https://github.com/chubes4/ai-http-client.git main --squash\n```\n\n**Manual Installation**: Download and include in your WordPress plugin or theme\n\n**Requirements**: PHP 7.4+, WordPress environment\n\n## Upgrading from v1.x to v2.0\n\n**Breaking Changes**: All filter/action hooks renamed from `ai_*` to `chubes_ai_*` for WordPress.org compliance.\n\n### Automatic Migration\n\nAPI keys are automatically migrated on first admin page load:\n- Old option: `ai_http_shared_api_keys`\n- New option: `chubes_ai_http_shared_api_keys`\n- Old option deleted after 30 days\n\n### Hook Migration\n\nUpdate all references in your code:\n\n```php\n// OLD (v1.x)\napply_filters('ai_providers', [])\napply_filters('ai_provider_api_keys', null)\napply_filters('ai_models', $provider)\napply_filters('ai_tools', [])\napply_filters('ai_request', $request)\napply_filters('ai_file_to_base64', '', $path)\napply_filters('ai_http', [], $method, $url, $args)\n\n// NEW (v2.0)\napply_filters('chubes_ai_providers', [])\napply_filters('chubes_ai_provider_api_keys', null)\napply_filters('chubes_ai_models', $provider)\napply_filters('chubes_ai_tools', [])\napply_filters('chubes_ai_request', $request)\napply_filters('chubes_ai_file_to_base64', '', $path)\napply_filters('chubes_ai_http', [], $method, $url, $args)\n```\n\nSee [docs/CHANGELOG.md](docs/CHANGELOG.md) for complete migration details.\n\n## Usage\n\n**Include Library**:\n```php\n// Composer: Auto-loads via Composer (no includes needed)\n\n// Git Subtree/Manual: Include in your plugin\nrequire_once plugin_dir_path(__FILE__) . 'lib/ai-http-client/ai-http-client.php';\n```\n\n**Basic Request**:\n```php\n$response = apply_filters('chubes_ai_request', [\n    'messages' =\u003e [['role' =\u003e 'user', 'content' =\u003e 'Hello AI!']]\n], 'openai'); // Provider name is now required\n```\n\n**Advanced Options**:\n```php\n// Specific provider (required parameter)\n$response = apply_filters('chubes_ai_request', $request, 'anthropic');\n\n// With streaming callback\n$response = apply_filters('chubes_ai_request', $request, 'openai', $streaming_callback);\n\n// With function calling tools\n$response = apply_filters('chubes_ai_request', $request, 'openai', null, $tools);\n\n// With conversation continuation\n$response = apply_filters('chubes_ai_request', $request, 'openai', null, $tools, $conversation_data);\n```\n\n## Providers\n\nComprehensive AI provider support with dynamic model discovery:\n\n- **OpenAI** - GPT models, OpenAI Responses API, streaming, function calling, native Files API integration\n- **Anthropic** - Claude models, streaming, function calling, native Files API integration with vision support\n- **Google Gemini** - Gemini models, streaming, function calling, native Files API integration with vision support\n- **Grok/X.AI** - Grok models, streaming support\n- **OpenRouter** - 200+ models via unified API gateway\n\n## Architecture\n\n- **Filter-Based**: WordPress-native provider registration via `chubes_ai_providers` filter\n- **Self-Contained**: Each provider handles format conversion internally (standard ↔ provider format)\n- **Unified Interface**: All providers accept standard format, return normalized responses\n- **WordPress-Native**: Uses wp_remote_* for HTTP, WordPress transients for caching\n- **Modular Design**: Provider files self-register, no central coordination needed\n- **Error Handling**: Comprehensive error hook via `chubes_ai_library_error` action\n- **Performance**: 24-hour model caching with granular cache clearing\n\n### Multi-Plugin Support\n\n- Plugin-isolated configurations via filter-based settings\n- Centralized API key storage in `chubes_ai_http_shared_api_keys` option\n- Multisite network-wide API key storage support\n- No provider conflicts through self-contained architecture\n- Independent AI settings per consuming plugin\n\n### Core Components\n\n- **Providers**: Self-contained classes with unified interface (OpenAI, Anthropic, Gemini, Grok, OpenRouter)\n- **Request Processing**: Complete pipeline via `chubes_ai_request` filter with error handling\n- **HTTP Layer**: Centralized `chubes_ai_http` filter supporting streaming and standard requests\n- **Caching System**: Model caching via `AIHttpCache` class with WordPress transients\n- **REST API**: Configuration and management endpoints via `ai_http_client` namespace\n- **Error Management**: Centralized logging via `AIHttpError` class\n\n## Core Filters\n\n```php\n// Provider Discovery\n$providers = apply_filters('chubes_ai_providers', []);\n\n// API Keys Management\n$keys = apply_filters('chubes_ai_provider_api_keys', null); // Get all keys\napply_filters('chubes_ai_provider_api_keys', $new_keys);     // Update all keys\n\n// Dynamic Model Fetching (with 24-hour cache)\n$models = apply_filters('chubes_ai_models', $provider_name, $config);\n\n// AI Tools Registration\n$tools = apply_filters('chubes_ai_tools', []);\n\n// File Operations\n$base64 = apply_filters('chubes_ai_file_to_base64', '', $file_path, $options);\n\n// HTTP Requests (internal use)\n$result = apply_filters('chubes_ai_http', [], 'POST', $url, $args, 'Context');\n```\n\n## REST API Endpoints\n\nThe library provides REST API endpoints for configuration and management:\n\n```php\n// Configure API keys via REST API\nwp_remote_post('/wp-json/ai-http-client/v1/api-keys/openai', [\n    'body' =\u003e wp_json_encode([\n        'api_key' =\u003e 'your-api-key'\n    ]),\n    'headers' =\u003e [\n        'Content-Type' =\u003e 'application/json',\n        'X-WP-Nonce' =\u003e wp_create_nonce('wp_rest')\n    ]\n]);\n\n// Get provider configuration\n$config = wp_remote_get('/wp-json/ai-http-client/v1/api-keys/openai', [\n    'headers' =\u003e [\n        'X-WP-Nonce' =\u003e wp_create_nonce('wp_rest')\n    ]\n]);\n\n// Get available models for a provider\n$models = wp_remote_get('/wp-json/ai-http-client/v1/models/openai', [\n    'headers' =\u003e [\n        'X-WP-Nonce' =\u003e wp_create_nonce('wp_rest')\n    ]\n]);\n\n// Get all available providers\n$providers = wp_remote_get('/wp-json/ai-http-client/v1/providers', [\n    'headers' =\u003e [\n        'X-WP-Nonce' =\u003e wp_create_nonce('wp_rest')\n    ]\n]);\n```\n\n**Available Endpoints:**\n- **GET/POST** `/wp-json/ai-http-client/v1/api-keys/{provider}` - Get/set API key for specific provider\n- **GET** `/wp-json/ai-http-client/v1/models/{provider}` - Get available models for a provider\n- **GET** `/wp-json/ai-http-client/v1/providers` - List all available providers\n\n## Multi-Plugin Configuration\n\n**Shared API Keys Storage**:\n```php\n// WordPress option: 'chubes_ai_http_shared_api_keys'\n$shared_keys = apply_filters('chubes_ai_provider_api_keys', null);\n// Returns: ['openai' =\u003e 'sk-...', 'anthropic' =\u003e 'sk-ant-...', ...]\n```\n\n**Provider Configuration**:\n```php\n// Each provider accepts configuration in constructor\n$provider = new AI_HTTP_OpenAI_Provider([\n    'api_key' =\u003e 'sk-...',\n    'organization' =\u003e 'org-...',\n    'base_url' =\u003e 'https://api.openai.com/v1' // Optional custom endpoint\n]);\n```\n\n## AI Tools System\n\n**Tool Registration**:\n```php\nadd_filter('chubes_ai_tools', function($tools) {\n    $tools['file_processor'] = [\n        'class' =\u003e 'FileProcessor_Tool',\n        'category' =\u003e 'file_handling',\n        'description' =\u003e 'Process files and extract content',\n        'parameters' =\u003e [\n            'file_path' =\u003e [\n                'type' =\u003e 'string',\n                'required' =\u003e true,\n                'description' =\u003e 'Path to file to process'\n            ]\n        ]\n    ];\n    return $tools;\n});\n```\n\n**Tool Discovery and Usage**:\n```php\n// Get all registered tools\n$all_tools = apply_filters('chubes_ai_tools', []);\n\n// Pass tools to AI request\n$response = apply_filters('chubes_ai_request', $request, 'openai', null, $tools);\n// Note: Tool execution is handled by consuming plugins\n```\n\n## Distribution\n\n- **Packagist**: Available via `composer require chubes4/ai-http-client`\n- **GitHub**: https://github.com/chubes4/ai-http-client\n- **Version**: 2.0.7 - Professional WordPress library with BaseProvider architecture\n- **License**: GNU GPL v3\n- **Dependencies**: None (pure WordPress integration)\n- **Multi-plugin**: Safe for concurrent use by multiple WordPress plugins\n\n### Adding Providers\n\n```php\nclass AI_HTTP_MyProvider {\n    public function __construct($config = []) { /* Provider setup */ }\n    public function is_configured() { /* Check if ready */ }\n    public function request($standard_request) { /* Standard → Provider → Standard */ }\n    public function streaming_request($standard_request, $callback) { /* Streaming support */ }\n    public function get_normalized_models() { /* Get models for UI */ }\n    public function get_raw_models() { /* Get raw API response */ }\n}\n\n// Self-register via filter\nadd_filter('chubes_ai_providers', function($providers) {\n    $providers['myprovider'] = [\n        'class' =\u003e 'AI_HTTP_MyProvider',\n        'type' =\u003e 'llm',\n        'name' =\u003e 'My Provider'\n    ];\n    return $providers;\n});\n```\n\n## Version 2.0.0 Features\n\n**WordPress.org Compliance**:\n- All filter/action hooks renamed from `ai_*` to `chubes_ai_*` prefix\n- Automatic migration system for API keys and settings\n- Backward compatibility migration for 30-day rollback window\n\n**Core Architecture**:\n- WordPress filter-based provider registration with self-contained classes\n- Unified request/response format across all providers\n- Comprehensive caching system with 24-hour model cache TTL\n- Native Files API integration for multi-modal content (text, images, files)\n- Streaming and standard request modes with proper error handling\n- REST API endpoints for configuration and management\n- Multisite network-wide API key storage support\n\n**AI Provider Support**:\n- OpenAI Responses API integration with native Files API support\n- Anthropic Claude models with dynamic model discovery and native Files API\n- Google Gemini with native Files API and multi-modal support\n- Grok/X.AI integration with streaming support\n- OpenRouter gateway access to 200+ models\n\n**WordPress Integration**:\n- Native WordPress HTTP API usage with centralized `chubes_ai_http` filter\n- WordPress transients for model caching with granular cache clearing\n- WordPress options API for settings with multisite support\n- Comprehensive error handling via `chubes_ai_library_error` action hook\n\n## Production Usage\n\nThis library is actively used in production WordPress plugins:\n\n- **Data Machine** - AI-powered content processing pipelines with multi-provider support\n- **WordSurf** - AI content editor with streaming responses and function calling\n- **AI Bot for bbPress** - Forum AI responses with contextual conversation management\n\n## Debug\n\n```php\ndefine('WP_DEBUG', true);\ndefine('WP_DEBUG_LOG', true);\n```\n\n**Debug Logging Covers**:\n- HTTP request/response cycles via `chubes_ai_http` filter\n- Provider-specific API interactions\n- Model caching operations and cache hits/misses\n- Streaming request handling\n- Error conditions via `chubes_ai_library_error` action hook\n- File upload operations to provider APIs\n\n## Contributing\n\nPull requests welcome for:\n- Additional AI provider integrations\n- Performance optimizations and caching improvements\n- WordPress compatibility enhancements\n- Template component additions\n- Documentation improvements\n\n## License\n\nGNU GPL v3 - **[Chris Huber](https://chubes.net)**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchubes4%2Fai-http-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchubes4%2Fai-http-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchubes4%2Fai-http-client/lists"}