Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save makowskid/928a3df53f1b75fa696e6f95cdb88c57 to your computer and use it in GitHub Desktop.

Select an option

Save makowskid/928a3df53f1b75fa696e6f95cdb88c57 to your computer and use it in GitHub Desktop.
SharpAPI.com PHP Client AI workflow API: Proofread Text Method Example

SharpAPI.com PHP Client AI workflow API: Proofread Text Method Example

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."
      }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment