API Details: Proofread & Grammar Checker AI API
Description: Shows how to use the proofread() method to check grammar and spelling errors in provided text.
Code Snippet:
<?php
require 'vendor/autoload.php';
use SharpAPI\SharpApiService;
// Load environment variables
$apiKey = getenv('SHARP_API_KEY');
if (!$apiKey) {
throw new Exception("API key not found. Please set SHARP_API_KEY in your environment variables.");
}
// Initialize the SharpApiService
$sharpApi = new SharpApiService($apiKey);
$textToProofread = "This is a txt with erors that need to be corected.";
try {
$statusUrl = $sharpApi->proofread($textToProofread);
$resultJob = $sharpApi->fetchResults($statusUrl);
echo "Proofread Text Result:\n";
print_r(json_decode($resultJob->getResultJson(), true));
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}$resultJob->getResultJson() format example:
{
"data": {
"type": "api_job_result",
"id": "2432f9ee-528a-4709-9916-2ab031df27ab",
"attributes": {
"status": "success",
"type": "content_proofread",
"result": "This is a text with errors that need to be corrected."
}
}
}