# Quickstart: your first Zoo API call from Rust

This guide takes you from an empty directory to a successful API call in
about five minutes.

## 1. Get an API token

1. Sign in at [zoo.dev](https://zoo.dev).
2. Open **Account → API tokens** and create a token.
3. Export it (the client checks `ZOO_API_TOKEN`, then `KITTYCAD_API_TOKEN`):

```bash
export ZOO_API_TOKEN="your-token"
```

## 2. Create a project

```bash
cargo new zoo-hello && cd zoo-hello
cargo add kittycad anyhow
cargo add tokio --features rt,macros
cargo add bytes
```

## 3. Verify authentication

Replace `src/main.rs` with:

```rust,no_run
#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let client = kittycad::Client::new_from_env();
    let me = client.users().get_self().await?;
    println!("authenticated as: {:?}", me);
    Ok(())
}
```

```bash
cargo run
```

If you see your account details, the token works. A
`401`-carrying `Error::Server` here means the token is missing or wrong.

## 4. Do something real: convert a CAD file

The file API converts between CAD formats server-side — no local CAD kernel
needed. This converts a STEP file to STL:

```rust,no_run
use kittycad::types::{FileExportFormat, FileImportFormat};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let client = kittycad::Client::new_from_env();
    let input = std::fs::read("part.step")?;

    let conversion = client
        .file()
        .create_conversion(
            FileExportFormat::Stl,            // what you want
            FileImportFormat::Step,           // what you have
            &bytes::Bytes::from(input),       // raw file bytes
        )
        .await?;

    println!("conversion status: {:?}", conversion.status);
    Ok(())
}
```

Small conversions usually complete synchronously; the returned
`FileConversion` carries the status, and completed output is returned
base64-encoded in the response's outputs map.

## 5. Where to go next

- **Worked examples** (units, account, pagination): [EXAMPLES.md](EXAMPLES.md)
- **Every endpoint**: [docs.rs/kittycad](https://docs.rs/kittycad)
- **The underlying HTTP API**: [zoo.dev/docs/api](https://zoo.dev/docs/api)

## Troubleshooting

| Symptom | Likely cause |
|---|---|
| `Error::Server { status: 401, .. }` | Token missing/expired — re-check step 1 |
| `new_from_env()` panics | Neither `ZOO_API_TOKEN` nor `KITTYCAD_API_TOKEN` is set |
| Conversion returns an error status | Source format doesn't match the bytes you sent |
