doctorcode / sdk
AI-powered error detection and fixing for PHP applications. Automatically captures errors and provides intelligent fixes using Claude, GPT-4, Grok, or Gemini.
Requires
- php: ^8.2
- guzzlehttp/guzzle: ^7.8
- illuminate/support: ^11.0
Requires (Dev)
- orchestra/testbench: ^9.0
- phpunit/phpunit: ^11.0
README
DoctorCode SDK
AI-powered error fixing for PHP and Laravel applications.
Zero-Configuration Installation
composer require doctorcode/sdk
That's it! The SDK automatically integrates with your Laravel application through service provider auto-discovery.
How It Works
- Install the SDK - One command, no configuration files to edit
- Register at doctorcode.dev - Create your free account
- Add Your LLM API Keys - Manage your Claude, OpenAI, Grok, or Gemini keys through the web dashboard
- Done! - All errors are automatically reported and analyzed by your chosen AI provider
Dashboard-Based Key Management
Instead of editing .env files, manage your LLM provider API keys through the user-friendly web dashboard at doctorcode.dev/dashboard.
Why Dashboard Management?
- Accessible to Everyone - No need to edit configuration files
- Privacy-First - Bring Your Own Keys (BYOK) model
- Multi-LLM Support - Switch between Claude Sonnet 4, GPT-4o, Grok, and Gemini Pro
- Secure - Keys encrypted at rest using Laravel encryption
- Multi-Application - Manage keys for all your applications from one place
Adding Your LLM Keys
- Visit doctorcode.dev/dashboard/api-keys
- Click "Add LLM Provider"
- Select your provider (Claude, OpenAI, Grok, or Gemini)
- Paste your API key
- Save - your applications will automatically use this key
Supported LLM Providers
| Provider | Model | Key Format |
|---|---|---|
| Claude | Sonnet 4 | sk-ant-... |
| OpenAI | GPT-4o | sk-... |
| Grok | Grok-2 | xai-... |
| Gemini | Pro | AIza... |
Features
Automatic Error Reporting
All uncaught PHP exceptions are automatically captured and sent to DoctorCode for analysis. No manual reporting required.
AI-Powered Fix Generation
Choose your preferred LLM provider. Each error is analyzed and a working fix is generated in ~30 seconds.
Privacy-First Architecture
- BYOK (Bring Your Own Keys) - You provide your own LLM API keys
- No Code Uploaded - Only error messages and stack traces are sent
- Encrypted Storage - All API keys encrypted using Laravel encryption
- Full Control - Manage and revoke keys anytime through the dashboard
Smart Error Detection
The SDK automatically filters out common exceptions like:
- Authentication errors
- Validation failures
- 404 Not Found errors
- Method Not Allowed errors
Environment-Aware
By default, errors are only reported in production environment. You can customize this behavior.
Requirements
- PHP 8.2 or higher
- Laravel 11.0 or higher
Advanced Configuration (Optional)
If you need to customize the SDK behavior, publish the configuration file:
php artisan vendor:publish --tag=doctorcode-config
This creates config/doctorcode.php with these options:
return [ // Base URL for DoctorCode API 'api_url' => env('DOCTORCODE_API_URL', 'https://doctorcode.dev/api'), // Enable/disable error reporting 'enabled' => env('DOCTORCODE_ENABLED', true), // Report errors in local environment 'report_local' => env('DOCTORCODE_REPORT_LOCAL', false), // Exceptions to skip reporting 'dont_report' => [ \Illuminate\Auth\AuthenticationException::class, \Illuminate\Validation\ValidationException::class, ], ];
Manual Error Reporting
You can manually report errors using the DoctorCode client:
use DoctorCode\SDK\DoctorCodeClient; $doctorCode = app(DoctorCodeClient::class); try { // Your code here } catch (\Exception $e) { $doctorCode->reportError( message: $e->getMessage(), file: $e->getFile(), line: $e->getLine(), stackTrace: $e->getTraceAsString() ); throw $e; }
Getting Fix Suggestions
use DoctorCode\SDK\DoctorCodeClient; $doctorCode = app(DoctorCodeClient::class); // Report an error and get the error ID $errorId = $doctorCode->reportError( message: 'Call to undefined method', file: 'app/Services/UserService.php', line: 42, stackTrace: $stackTrace ); // Get AI-generated fix $fix = $doctorCode->getFixSuggestion($errorId); if ($fix['success']) { echo "Suggested fix:\n"; echo $fix['fixed_code']; echo "\n\nExplanation:\n"; echo $fix['explanation']; }
How Error Analysis Works
When an error occurs:
- SDK captures the error - Automatically through exception handler
- Error sent to DoctorCode - Encrypted connection to DoctorCode API
- Your LLM key retrieved - Platform fetches your chosen LLM provider key
- AI analyzes the error - Using Claude, GPT-4o, Grok, or Gemini
- Fix generated - Working code solution with explanation
- Fix returned to you - View in dashboard or via API
Cost Control
Since you provide your own LLM API keys (BYOK model), you have complete control over costs:
- Claude API - ~$0.003 per error fix (Sonnet 4)
- OpenAI API - ~$0.002 per error fix (GPT-4o)
- Grok API - ~$0.001 per error fix
- Gemini API - Free tier available
You can monitor your API usage directly through your LLM provider's dashboard.
Security Best Practices
- Never commit API keys to version control
- Use dashboard to manage keys - Easier than managing
.envfiles - Rotate keys periodically - Easy to update through dashboard
- Use application-specific keys - Different keys for different apps if needed
- Monitor key usage - Check
last_used_attimestamp in dashboard
Community & Fix Sharing
DoctorCode builds a knowledge base of fixes. When an error has been fixed before:
- Instant fixes - No LLM call needed for known errors
- Improved accuracy - Learn from community-validated solutions
- Cost savings - Fewer LLM API calls
Troubleshooting
SDK Not Reporting Errors
- Check that you're in
productionenvironment (or setDOCTORCODE_REPORT_LOCAL=true) - Verify you've added an LLM API key at doctorcode.dev/dashboard
- Check Laravel logs for any DoctorCode connection errors
"No LLM Keys Configured" Message
Visit doctorcode.dev/dashboard/api-keys and add your preferred LLM provider's API key.
Invalid API Key Format
Make sure your API key matches the provider's format:
- Claude:
sk-ant-api03-... - OpenAI:
sk-... - Grok:
xai-... - Gemini:
AIza...
Support
- Documentation: docs.doctorcode.dev
- Issues: github.com/CLEDAI/doctor-code/issues
- Dashboard: doctorcode.dev/dashboard
License
MIT License - see LICENSE file for details.
Contributing
Contributions are welcome! Please see our contributing guidelines.
Get Started: https://doctorcode.dev