> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stealthgpt.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Code Examples

> Explore practical examples of integrating and using the StealthGPT API in different programming languages

## Python

<Tabs>
  <Tab title="Content Generation">
    ```python theme={null}
    import requests

    def generate_content(prompt, tone=None, mode=None, is_multilingual=True, detector=None):
        """
        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
            is_multilingual (bool, optional): For non-English input, whether to translate the final result back into the original language (True) or keep it in English (False)
            detector (str, optional): Deprecated. Kept for backward compatibility only and has no effect on model behavior.

        Returns:
            str: Generated content

        Note:
            For premium long-form output, use POST /api/stealthify/agent instead.
            See https://stealthgpt.ai docs: api-reference/stealth-agent/guide
        """
        api_token = 'YOUR_API_TOKEN'
        url = 'https://stealthgpt.ai/api/stealthify'

        payload = {
            'prompt': prompt,
            'rephrase': False
        }

        if tone:
            payload['tone'] = tone
        if mode:
            payload['mode'] = mode
        if not is_multilingual:
            payload['isMultilingual'] = is_multilingual
        if detector:
            payload['detector'] = detector
            
        # 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",
        detector="turnitin"
    )
    print(content)
    ```
  </Tab>

  <Tab title="Content Rephrasing">
    ```python theme={null}
    import requests

    def rephrase_content(text, tone=None, mode=None, is_multilingual=True, detector=None):
        """
        Rephrase content using StealthGPT API

        Args:
            text (str): The text to rephrase
            tone (str, optional): Standard, HighSchool, College, or PhD
            mode (str, optional): High, Medium, or Low detail level
            is_multilingual (bool, optional): For non-English input, whether to translate the final result back into the original language (True) or keep it in English (False)
            detector (str, optional): Deprecated. Kept for backward compatibility only and has no effect on model behavior.

        Returns:
            str: Rephrased content
        """
        api_token = 'YOUR_API_TOKEN'
        url = 'https://stealthgpt.ai/api/stealthify'

        payload = {
            'prompt': text,
            'rephrase': True
        }

        if tone:
            payload['tone'] = tone
        if mode:
            payload['mode'] = mode
        if not is_multilingual:
            payload['isMultilingual'] = is_multilingual
        if detector:
            payload['detector'] = detector
            
        # 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
    rephrased = rephrase_content(
        text="Artificial intelligence is transforming many industries by automating tasks that previously required human intelligence.",
        tone="PhD"
    )
    print(rephrased)
    ```
  </Tab>

  <Tab title="Article Generation">
    ```python theme={null}
    import requests

    def generate_article(topic, with_images=True, size="medium", is_multilingual=True):
        """
        Generate a complete blog article using StealthGPT API
        
        Args:
            topic (str): The topic for the article
            with_images (bool, optional): Whether to include images
            size (str, optional): "small", "medium", or "long"
            is_multilingual (bool, optional): For non-English input, whether to translate the final article back into the original language (True) or keep it in English (False)
            
        Returns:
            str: Markdown content of the generated article
        """
        api_token = 'YOUR_API_TOKEN'
        url = 'https://stealthgpt.ai/api/stealthify/articles'
        
        # Prepare request payload
        payload = {
            'prompt': topic,
            'withImages': with_images,
            'size': size
        }
        
        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
    article = generate_article(
        topic="The future of remote work in the tech industry",
        size="medium"
    )
    print(article)
    ```
  </Tab>
</Tabs>

## Node.js

<Tabs>
  <Tab title="Content Generation">
    ```javascript theme={null}
    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.isMultilingual - For non-English input, whether to translate the final result back into the original language (true) or keep it in English (false)
     * @param {string} options.detector - Deprecated. Kept for backward compatibility only and has no effect on model behavior.
     * @returns {Promise<string>} - Generated content
     *
     * Note: For premium long-form output, use POST /api/stealthify/agent instead.
     * See: api-reference/stealth-agent/guide
     */
    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',
        detector: 'turnitin'
      }
    )
      .then(content => console.log(content))
      .catch(error => console.error(error));
    ```
  </Tab>

  <Tab title="Content Rephrasing">
    ```javascript theme={null}
    const axios = require('axios');

    /**
     * Rephrase content using StealthGPT API
     * 
     * @param {string} text - The text to rephrase
     * @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.isMultilingual - For non-English input, whether to translate the final result back into the original language (true) or keep it in English (false)
     * @param {string} options.detector - Deprecated. Kept for backward compatibility only and has no effect on model behavior.
     * @returns {Promise<string>} - Rephrased content
     */
    async function rephraseContent(text, options = {}) {
      const apiToken = 'YOUR_API_TOKEN';
      const url = 'https://stealthgpt.ai/api/stealthify';
      
      // Prepare request payload
      const payload = {
        prompt: text,
        rephrase: true,
        ...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
    rephraseContent(
      'Artificial intelligence is transforming many industries by automating tasks that previously required human intelligence.',
      {
        tone: 'PhD',
        detector: 'gptzero'
      }
    )
      .then(content => console.log(content))
      .catch(error => console.error(error));
    ```
  </Tab>

  <Tab title="Article Generation">
    ```javascript theme={null}
    const axios = require('axios');

    /**
     * Generate a complete blog article using StealthGPT API
     * 
     * @param {string} topic - The topic for the article
     * @param {Object} options - Optional parameters
     * @param {boolean} options.withImages - Whether to include images
     * @param {string} options.size - "small", "medium", or "long"
     * @param {boolean} options.isMultilingual - For non-English input, whether to keep output in original language (true) or in English (false)
     * @returns {Promise<string>} - Markdown content of the generated article
     */
    async function generateArticle(topic, options = {}) {
      const apiToken = 'YOUR_API_TOKEN';
      const url = 'https://stealthgpt.ai/api/stealthify/articles';
      
      // Prepare request payload with defaults
      const payload = {
        prompt: topic,
        withImages: options.withImages !== undefined ? options.withImages : true,
        size: options.size || 'medium',
        isMultilingual: options.isMultilingual !== undefined ? options.isMultilingual : true
      };
      
      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
    generateArticle(
      'The future of remote work in the tech industry',
      { size: 'medium' }
    )
      .then(article => console.log(article))
      .catch(error => console.error(error));
    ```
  </Tab>
</Tabs>

## Ruby

<Tabs>
  <Tab title="Content Generation">
    ```ruby theme={null}
    require 'net/http'
    require 'uri'
    require 'json'

    def generate_content(prompt, tone: nil, mode: nil, is_multilingual: true, detector: nil)
      api_token = 'YOUR_API_TOKEN'
      url = URI.parse('https://stealthgpt.ai/api/stealthify')

      payload = {
        prompt: prompt,
        rephrase: false
      }

      payload[:tone] = tone if tone
      payload[:mode] = mode if mode
      payload[:isMultilingual] = is_multilingual unless is_multilingual
      payload[:detector] = detector if detector
      
      # 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
    ```
  </Tab>

  <Tab title="Content Rephrasing">
    ```ruby theme={null}
    require 'net/http'
    require 'uri'
    require 'json'

    def rephrase_content(text, tone: nil, mode: nil, is_multilingual: true)
      api_token = 'YOUR_API_TOKEN'
      url = URI.parse('https://stealthgpt.ai/api/stealthify')

      payload = {
        prompt: text,
        rephrase: true
      }

      payload[:tone] = tone if tone
      payload[:mode] = mode if mode
      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
    rephrased = rephrase_content(
      "Artificial intelligence is transforming many industries by automating tasks that previously required human intelligence.",
      tone: "PhD"
    )
    puts rephrased
    ```
  </Tab>

  <Tab title="Article Generation">
    ```ruby theme={null}
    require 'net/http'
    require 'uri'
    require 'json'

    def generate_article(topic, with_images: true, size: 'medium', is_multilingual: true)
      api_token = 'YOUR_API_TOKEN'
      url = URI.parse('https://stealthgpt.ai/api/stealthify/articles')
      
      # Prepare request payload
      payload = {
        prompt: topic,
        withImages: with_images,
        size: size
      }
      
      # Add multilingual parameter only if false (since true is default)
      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
    article = generate_article(
      "The future of remote work in the tech industry",
      size: "medium"
    )
    puts article
    ```
  </Tab>
</Tabs>

## Additional Languages

For examples in other programming languages or for more complex integration scenarios, please refer to the following resources:

* [API Reference Documentation](/api-reference/endpoints/stealthify)
