# Detect AI-Generated Text

> Check whether text is human-written or AI-generated with one synchronous Copyleaks API call - submit text and get a classification instantly.

The Copyleaks [AI Detector](https://copyleaks.com/ai-detector) API is a powerful tool to determine if a given text was written by a human or generated by an AI. The API is synchronous, meaning you get the results in the same API call.

This guide will walk you through the process of submitting text for [AI detection](https://copyleaks.com/ai-detector) and understanding the results.

## Get started

<Steps>
  <Step>
    ### Before you begin
    Before you start, ensure you have the following:
    - An active Copyleaks account. If you don't have one, **[sign up for free](https://api.copyleaks.com/signup)**.
    - You can find your API key on the **[API Dashboard](https://api.copyleaks.com/dashboard)**.
  </Step>

  <Step>
    ### Installation
    <InstallSDKs />
  </Step>

  <Step>
    ### Login
    <GuideLogin />
  </Step>

  <Step>
    ### Submit for analysis
    Use the [AI Text Detection Endpoint](/reference/actions/writer-detector/check) to send text for analysis. We suggest you provide a unique `scanId` for each submission.

    <Tip>
    For testing, set `"sandbox": true`. Sandbox mode is free and returns mock results.
    </Tip>
    
    <CodeGroup>
    ```http title="HTTP" icon="globe"
    POST https://api.copyleaks.com/v2/writer-detector/my-scan-1/check

    Headers
    Authorization: Bearer <YOUR_AUTH_TOKEN>
    Content-Type: application/json

    Body
    {
      "text": "Lions are social animals, living in groups called prides, typically consisting of several females, their offspring, and a few males. Female lions are the primary hunters, working together to catch prey. Lions are known for their strength, teamwork, and complex social structures.",
      "sandbox": true
    }
    ```
      ```bash title="cURL" icon="terminal"
      curl -X POST "https://api.copyleaks.com/v2/writer-detector/my-scan-1/check" \
           -H "Authorization: Bearer <YOUR_AUTH_TOKEN>" \
           -H "Content-Type: application/json" \
           -d '{
                 "text": "Lions are social animals, living in groups called prides, typically consisting of several females, their offspring, and a few males. Female lions are the primary hunters, working together to catch prey. Lions are known for their strength, teamwork, and complex social structures.",
                 "sandbox": true
               }'
      ```
      ```python title="Python" icon="python"
      from copyleaks.copyleaks import Copyleaks
      from copyleaks.models.submit.ai_detection_document import NaturalLanguageDocument, SourceCodeDocument

      scan_id = "my-scan-1"
      sample_text = "Lions are social animals, living in groups called prides, typically consisting of several females, their offspring, and a few males. Female lions are the primary hunters, working together to catch prey. Lions are known for their strength, teamwork, and complex social structures."
      
      natural_language_submission = NaturalLanguageDocument(sample_text)
      natural_language_submission.set_sandbox(True)
      response = Copyleaks.AiDetectionClient.submit_natural_language(auth_token, scan_id, natural_language_submission)
      print(response)
      ```
      ```javascript title="JavaScript" icon="square-js"
      const { Copyleaks, CopyleaksNaturalLanguageSubmissionModel } = require('plagiarism-checker');

      async function checkAiText() {
          try {
              // Initialize Copyleaks
              const copyleaks = new Copyleaks();

              // Login to get the authentication token.
              // Replace with your email and API key.
              const loginResult = await copyleaks.loginAsync('YOUR_EMAIL@example.com', 'YOUR_API_KEY');

              const scanId = `ai-text-scan-${Date.now()}`;
              
              // The text to be checked
              const textToCheck = "Lions are social animals, living in groups called prides, typically consisting of several females, their offspring, and a few males. Female lions are the primary hunters, working together to catch prey.";

              // Create a submission model
              const submission = new CopyleaksNaturalLanguageSubmissionModel(textToCheck);
              submission.sandbox = true; // Use sandbox for testing

              // Submit the text for analysis
              const response = await copyleaks.aiDetectionClient.submitNaturalTextAsync(loginResult, scanId, submission);
              console.log("AI detection results:", response);

          } catch (error) {
              console.error("An error occurred:", error);
          }
      }

      checkAiText();
      ```
      ```java title="Java" icon="java"
      import classes.Copyleaks;
      import models.submissions.CopyleaksNaturalLanguageSubmissionModel;
      import models.responses.AIDetectionResponse;

      String scanId = "my-ai-scan";
      String sampleText = "Lions are social animals, living in groups called prides...";

      CopyleaksNaturalLanguageSubmissionModel submission = new CopyleaksNaturalLanguageSubmissionModel(sampleText);
      submission.setSandbox(true);
      
      AIDetectionResponse response = Copyleaks.aiDetectionClient.submitNaturalLanguage(authToken, scanId, submission);
      System.out.println("AI Score: " + response.getSummary().getAi());
      ```
    </CodeGroup>
  </Step>

  <Step>
    ### Interpreting the response
    For a complete breakdown of the response structure, see the [AI Detection Response](/reference/data-types/ai-detector/ai-text-detector-response)
    documentation.
  </Step>

  <Step>
    ### Summary
    You have successfully submitted text for AI detection. You can now use the JSON response in your application to take further action based on the findings.
  </Step>
</Steps>

## Frequently asked questions

<AccordionGroup>
  <Accordion title="Is the AI text detection API synchronous?">
    Yes. You send text to the [check endpoint](/reference/actions/writer-detector/check) and receive the detection results in the same API call, with no webhook required.
  </Accordion>
  <Accordion title="Which endpoint detects AI-generated text?">
    `POST https://api.copyleaks.com/v2/writer-detector/{scanId}/check`, with the text to analyze in the request body.
  </Accordion>
  <Accordion title="Can I test it for free?">
    Yes. Set `"sandbox": true` in the request. Sandbox mode is free and returns mock results so you can build the integration before going live.
  </Accordion>
  <Accordion title="What does the response contain?">
    A per-section classification (human or AI) and an overall human-versus-AI summary. See the [AI Detection Response](/reference/data-types/ai-detector/ai-text-detector-response) reference for the full structure.
  </Accordion>
  <Accordion title="How is this different from detecting AI in documents?">
    This endpoint analyzes raw text synchronously. To scan files such as PDF or DOCX, use the asynchronous authenticity flow in [Detect AI-Generated Content in Documents](/guides/authenticity/detect-ai-generated-content).
  </Accordion>
</AccordionGroup>

## Next steps
<CardGroup cols={2}>
    <Card title="API Reference" icon="code" href="/reference/actions/writer-detector/check">Explore the full API reference for the AI Detection endpoint.</Card>
    <Card title="AI Logic" icon="brain" href="/concepts/features/ai-logic/">Learn how to use AI logic can help you interpret the results of AI text detection.</Card>
    <Card title="Accuracy & 3rd Party Evaluations" icon="award" href="https://copyleaks.com/blog/ai-detector-continues-top-accuracy-third-party">Discover how Copyleaks AI Detector maintains top accuracy in third-party evaluations.</Card>
</CardGroup>
