# Rust SDK Quickstart

> Install the Copyleaks Rust SDK, authenticate, and submit your first scan in under 5 minutes with this step-by-step guide.

This guide will walk you through installing the official Rust SDK and running your first scan. In just a few minutes, you'll be able to check content for plagiarism, AI-generated text, moderation and more directly from your Rust application.

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)**.
- Rust 1.88 or later. The SDK is async and runs on Tokio.

## Get Started

<Steps>
  <Step title="Installation">
    Add the official `copyleaks` crate and Tokio to your project.

    ```bash
    cargo add copyleaks@2
    cargo add tokio --features macros,rt-multi-thread
    ```
  </Step>

  <Step title="Quick Example: Scan Text">
    <Warning>
    Remember to replace the placeholder credentials and webhook URL with your actual values.
    </Warning>

    ```rust title="src/main.rs"
    use copyleaks::plagiarism::{FileSubmission, ScanProperties};
    use copyleaks::Client;

    #[tokio::main]
    async fn main() -> Result<(), Box<dyn std::error::Error>> {
        let client = Client::new()?;

        // Log in to the Copyleaks API. The token is valid for 48 hours; reuse it.
        let token = client.login("YOUR_EMAIL_ADDRESS", "YOUR_API_KEY").await?;

        // {STATUS} is replaced with completed, error, creditschecked or indexed.
        let properties = ScanProperties::new("https://your-server.com/webhook/{STATUS}")
            .sandbox(true); // Turn on sandbox mode for testing

        // Submit a simple string of text for scanning
        let file = FileSubmission::from_bytes("Hello world, this is a test.", "test.txt", properties);
        client.submit_file(&token, "my-first-scan", &file).await?;
        println!("Scan submitted successfully! Scan ID: my-first-scan");
        println!("You will be notified via your webhook when the scan is complete.");
        Ok(())
    }
    ```
  </Step>

  <Step title="Understanding the Code">
    The example code performs four main actions to submit a scan:

    1.  **Create a client:** `Client::new()` creates the client that sends every request.
    2.  **Login:** It authenticates with your email and API key to get a login token, which is required for all subsequent requests.
    3.  **Configure Scan:** `ScanProperties::new` takes the webhook URL, and `.sandbox(true)` turns on sandbox mode for safe testing. `FileSubmission::from_bytes` takes the content, a filename and the properties; the SDK encodes the content to Base64 for you.
    4.  **Submit for Scanning:** `submit_file` sends the submission to the Copyleaks API. The process is asynchronous; Copyleaks will notify your webhook URL once the scan is complete.

    The request types are `#[non_exhaustive]`, so new API fields can arrive in minor releases. Build them with their constructors and chainable setters, not with struct literals.
  </Step>
</Steps>

## Next Steps

<CardGroup cols={3}>
  <Card title="GitHub Repository" icon="github" href="https://github.com/Copyleaks/copyleaks-rust">Check the official Copyleaks Rust SDK repository on GitHub for more examples and details.</Card>
  <Card title="crates.io Package" icon="rust" href="https://crates.io/crates/copyleaks">View the official crate on crates.io to see all available versions.</Card>
  <Card title="API Reference" icon="book" href="https://docs.rs/copyleaks">Browse every type and method of the SDK on docs.rs.</Card>
</CardGroup>

<CardGroup cols={2}>
  <Card title="Check for Plagiarism" icon="magnifying-glass" href="/guides/authenticity/detect-plagiarism-text">
    Detect plagiarism in text documents using the Copyleaks API. Search billions of sources to find unoriginal content.
  </Card>
  <Card title="Detect AI-Generated Content" icon="robot" href="/guides/ai-detector/ai-text-detection">
    Detect AI-generated text via sync or async API calls. This guide covers sync detection, see the Authenticity API Guide for async.
  </Card>
  <Card title="Assess Grammar and Writing Quality" icon="spell-check" href="/guides/writing/check-grammar">
    Get writing and grammar suggestions via API. Authenticate, submit text, and access full details in the docs.
  </Card>
  <Card title="Moderate Text" icon="shield-halved" href="/guides/moderation/moderate-text">
    Scan and moderate text content for unsafe or policy-relevant material across 10+ categories.
  </Card>
</CardGroup>
