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

# Authentication

> How to authenticate the SCANOSS Java SDK with an API key and configure a custom API endpoint.

## Default Behaviour

By default, the `Scanner` class connects to the SCANOSS OSS Knowledge Base API at
`https://api.osskb.org` without requiring any authentication.

## Using an API Key

When an API key is provided without a custom URL, the SDK automatically switches to
the SCANOSS Premium endpoint at `https://api.scanoss.com`. Pass the key using the
`.apiKey()` builder method:

```java theme={null}
import com.scanoss.Scanner;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = Scanner.builder()
                .apiKey("your-api-key")
                .build();

        List<String> results = scanner.scanFolder("/path/to/project");
        results.forEach(System.out::println);
    }
}
```

## Using a Custom API Endpoint

To direct the SDK to a different API endpoint, pass the full endpoint URL using
the `.url()` builder method:

```java theme={null}
import com.scanoss.Scanner;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = Scanner.builder()
                .url("https://your-custom-api-url")
                .build();

        List<String> results = scanner.scanFolder("/path/to/project");
        results.forEach(System.out::println);
    }
}
```

## Using an API Key with a Custom Endpoint

An API key and a custom endpoint URL can be used together. When a `url` is explicitly
set, it always takes precedence over the SCANOSS Premium endpoint
(`https://api.scanoss.com`):

```java theme={null}
import com.scanoss.Scanner;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = Scanner.builder()
                .url("https://your-custom-api-url")
                .apiKey("your-api-key")
                .build();

        List<String> results = scanner.scanFolder("/path/to/project");
        results.forEach(System.out::println);
    }
}
```
