chatgpt/doc
Laravel package that adds a /chatgpt-doc route to serve helpful OpenAI and ChatGPT documentation. Install via Composer; optionally register the service provider if auto-discovery is disabled. No specific PHP or Laravel version dependency.
Installation
composer require dev-arindam-roy/chatgpt-doc
Add the service provider to config/app.php:
'providers' => [
// ...
DevArindamRoy\ChatGPTDoc\ChatGPTDocServiceProvider::class,
],
Publish Config (Optional)
php artisan vendor:publish --provider="DevArindamRoy\ChatGPTDoc\ChatGPTDocServiceProvider"
Configure API keys and endpoints in config/chatgpt-doc.php.
First Use Case Fetch OpenAI API documentation dynamically in a controller:
use DevArindamRoy\ChatGPTDoc\Facades\ChatGPTDoc;
public function showDocs()
{
$docs = ChatGPTDoc::getDocumentation('completions');
return view('docs', ['docs' => $docs]);
}
Dynamic Documentation Fetching
// Fetch API reference for a specific endpoint
$completionsDocs = ChatGPTDoc::getDocumentation('completions');
// Fetch all available endpoints
$allEndpoints = ChatGPTDoc::listEndpoints();
Integration with Laravel Routes
Route::get('/docs/{endpoint}', function ($endpoint) {
return ChatGPTDoc::getDocumentation($endpoint);
})->name('api.docs');
Caching for Performance
// Cache docs for 1 hour
$docs = ChatGPTDoc::getDocumentation('models', 3600);
Blade Integration
@foreach($docs['parameters'] as $param)
<div class="param">
<strong>{{ $param['name'] }}</strong>: {{ $param['description'] }}
</div>
@endforeach
Custom Documentation Storage Extend the package to store fetched docs in a database:
ChatGPTDoc::storeDocumentation('models', $rawDocs);
API Versioning
// Fetch v1 docs
$v1Docs = ChatGPTDoc::getDocumentation('models', null, 'v1');
Event Listeners
Listen for ChatGPTDoc.Fetched events to log or process docs:
ChatGPTDoc::getDocumentation('files')->then(function ($docs) {
event(new DocsFetched($docs));
});
Rate Limiting
try {
$docs = ChatGPTDoc::getDocumentation('engines');
} catch (\DevArindamRoy\ChatGPTDoc\Exceptions\RateLimitExceeded $e) {
sleep($e->retryAfter);
retry();
}
Deprecated Endpoints
engines) are deprecated. Use ChatGPTDoc::isDeprecated('engines') to check.Configuration Overrides
.env:
CHATGPT_DOC_API_KEY=your_key_here
Enable Debug Mode
ChatGPTDoc::setDebug(true); // Logs HTTP requests/responses
Validate Responses
$docs = ChatGPTDoc::getDocumentation('files');
if (!ChatGPTDoc::isValidResponse($docs)) {
Log::error('Invalid docs response', ['response' => $docs]);
}
Custom Data Sources Override the default OpenAI source:
ChatGPTDoc::setSource(new CustomChatGPTDocSource());
Response Transformers Modify raw responses before processing:
ChatGPTDoc::setTransformer(function ($raw) {
return collect($raw)->map(fn ($item) => [
'name' => $item['id'],
'description' => $item['purpose'],
]);
});
Authentication Extend for enterprise/private API keys:
ChatGPTDoc::setAuth(new BearerTokenAuth('your_enterprise_key'));
Lazy Loading
Use ChatGPTDoc::lazyLoad('models') to fetch docs only when accessed in Blade:
@lazyLoad('models')
@include('partials.model-docs')
@endLazyLoad
Selective Field Loading
$docs = ChatGPTDoc::getDocumentation('files', null, null, ['id', 'description']);
How can I help you explore Laravel packages today?