GPT PHP Sample Code
Generate Unique Content

Learn how to create 100% original content using PHP with autoWrite's GPT API. There are no libraries or third party code required when you use our API. Any web server can be used to generate seo ready content with PHP.


PHP Sample Code

Copy the following PHP code and change your API key to run a quick example of content generation using the autoWrite API.


<?php
//Api Key: Get yours at https://autowrite.org/api-settings/
$autoWrite_apiKey = '0A062139-BF83-450A-BD8F-BC556D2874B5'; 
$autoWrite_apiSecret = '3A5DD1CE-1E63-49EA-8F4F-5259703F4CC3'; 

//Build your prompt:
$autoWrite_prompt = [
	'autoWrite_apikey' => $autoWrite_apiKey,
	'autoWrite_apisecret' => $autoWrite_apiSecret,
	'autoWrite_prompt' => 'Eating habbits of a frog',
	'autoWrite_mode' => 'blogpost', //optional
	'autoWrite_mode_model' => 'academic', //optional
	'autoWrite_token_limit' => 160, 
	'autoWrite_temperature' => 0.7, 
	'autoWrite_topP' => 1.0, 
	'autoWrite_drift' => 0.0, 
	'autoWrite_penalty_frequency' => 0.0, 
	'autoWrite_stop_sequence' => ''
];

//Submit the request:
$autoWrite_endpoint = 'https://autowrite.org/api/content/2.1/create';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$autoWrite_endpoint);  
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $autoWrite_prompt);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$autoWrite_data = curl_exec($ch);
curl_close($ch);
$autoWrite_result = json_decode($autoWrite_data);
//Handle the response:
if($autoWrite_result->status == 'success') {	
	echo $autoWrite_result->response;
} else {
	echo 'Invalid Request to autoWrite.org API ('.$autoWrite_result->status.'): '.$autoWrite_result->response;
}
?>