Explore practical examples of integrating and using the StealthGPT API in different programming languages
import requests
def generate_content(prompt, tone=None, mode=None, business=False, is_multilingual=True):
"""
Generate content using StealthGPT API
Args:
prompt (str): The prompt for content generation
tone (str, optional): Standard, HighSchool, College, or PhD
mode (str, optional): High, Medium, or Low detail level
business (bool, optional): Whether to use business mode
is_multilingual (bool, optional): Whether to allow multilingual output
Returns:
str: Generated content
"""
api_token = 'YOUR_API_TOKEN'
url = 'https://stealthgpt.ai/api/stealthify'
# Prepare request payload
payload = {
'prompt': prompt,
'rephrase': False
}
# Add optional parameters if provided
if tone:
payload['tone'] = tone
if mode:
payload['mode'] = mode
if business:
payload['business'] = business
if not is_multilingual:
payload['isMultilingual'] = is_multilingual
# Set headers
headers = {
'api-token': api_token,
'Content-Type': 'application/json'
}
# Send request
response = requests.post(url, headers=headers, json=payload)
# Check for successful response
if response.status_code == 200:
return response.json()['result']
else:
raise Exception(f"Error {response.status_code}: {response.text}")
# Example usage
content = generate_content(
prompt="Explain the benefits of cloud computing for small businesses",
tone="College",
mode="Medium"
)
print(content)
const axios = require('axios');
/**
* Generate content using StealthGPT API
*
* @param {string} prompt - The prompt for content generation
* @param {Object} options - Optional parameters
* @param {string} options.tone - Standard, HighSchool, College, or PhD
* @param {string} options.mode - High, Medium, or Low detail level
* @param {boolean} options.business - Whether to use business mode
* @param {boolean} options.isMultilingual - Whether to allow multilingual output
* @returns {Promise<string>} - Generated content
*/
async function generateContent(prompt, options = {}) {
const apiToken = 'YOUR_API_TOKEN';
const url = 'https://stealthgpt.ai/api/stealthify';
// Prepare request payload
const payload = {
prompt,
rephrase: false,
...options
};
try {
// Send request
const response = await axios.post(url, payload, {
headers: {
'api-token': apiToken,
'Content-Type': 'application/json'
}
});
return response.data.result;
} catch (error) {
if (error.response) {
throw new Error(`Error ${error.response.status}: ${JSON.stringify(error.response.data)}`);
} else {
throw error;
}
}
}
// Example usage
generateContent(
'Explain the benefits of cloud computing for small businesses',
{
tone: 'College',
mode: 'Medium'
}
)
.then(content => console.log(content))
.catch(error => console.error(error));
require 'net/http'
require 'uri'
require 'json'
def generate_content(prompt, tone: nil, mode: nil, business: false, is_multilingual: true)
api_token = 'YOUR_API_TOKEN'
url = URI.parse('https://stealthgpt.ai/api/stealthify')
# Prepare request payload
payload = {
prompt: prompt,
rephrase: false
}
# Add optional parameters if provided
payload[:tone] = tone if tone
payload[:mode] = mode if mode
payload[:business] = business if business
payload[:isMultilingual] = is_multilingual unless is_multilingual
# Set up the HTTP request
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url.path)
request['api-token'] = api_token
request['Content-Type'] = 'application/json'
request.body = payload.to_json
# Send the request
response = http.request(request)
# Check for successful response
if response.code == '200'
return JSON.parse(response.body)['result']
else
raise "Error #{response.code}: #{response.body}"
end
end
# Example usage
content = generate_content(
"Explain the benefits of cloud computing for small businesses",
tone: "College",
mode: "Medium"
)
puts content