> For the complete documentation index, see [llms.txt](https://doc.ozforensics.com/oz-knowledge/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.ozforensics.com/oz-knowledge/guides/developer-guide/sdk/oz-mobile-sdk/android/connecting-sdk-to-api.md).

# Connecting SDK to API

To connect SDK to Oz API, specify the API URL, [access token](/oz-knowledge/guides/developer-guide/api/oz-api/use-cases/authentication.md), and [SSL pins](/oz-knowledge/guides/developer-guide/sdk/oz-mobile-sdk/android/android-sdk-methods-and-properties.md#sslpin) as shown below.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
OzLivenessSDK.setApiConnection(OzConnection.fromServiceToken(host, token, sslPins))
```

{% endtab %}

{% tab title="Java" %}

```java
OzLivenessSDK.INSTANCE.setApiConnection(
        OzConnection.Companion.fromServiceToken(host, token, sslPins), 
        null
);
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
Please note:

* In your host application, it is recommended that you set the API address on the screen that precedes the liveness check. Setting the API URL initiates a service call to the API, which may cause excessive server load when being done at the application initialization or startup. We recommend calling the `setApiConnection` method once, for example, in the `Application` class.
* The order of SDK initialization and API connection does not matter, but both methods must be finished successfully before invoking the `createStartIntent` method.
  {% endhint %}

Alternatively, you can use the login and password provided by your Oz Forensics account manager:

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
OzLivenessSDK.setApiConnection(
    OzConnection.fromCredentials(host, username, password, sslPins),
    statusListener(
        { token -> /* token */ },
        { ex -> /* error */ }
    )
)
```

{% endtab %}

{% tab title="Java" %}

```java
OzLivenessSDK.INSTANCE.setApiConnection(
        OzConnection.Companion.fromCredentials(host, username, password, sslPins),
        new StatusListener<String>() {
            @Override
            public void onStatusChanged(@Nullable String s) {}
            @Override
            public void onSuccess(String token) { /* token */ }
            @Override
            public void onError(@NonNull OzException e) { /* error */ }
        }
);
```

{% endtab %}
{% endtabs %}

Although, the preferred option is authentication via access token – for security reasons.

### Telemetry

By default, logs are saved along with the analyses' data. If you need to keep the logs distinct from the analysis data, [set up the separate connection](/oz-knowledge/guides/developer-guide/sdk/oz-mobile-sdk/android/android-sdk-methods-and-properties.md#seteventsconnection) for [telemetry](/oz-knowledge/other/faq.md#what-is-telemetry-and-why-should-i-use-it) as shown below.

{% hint style="warning" %}
Always establish the API connection first. If you connect to the API after telemetry, the telemetry token might get lost.
{% endhint %}

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
OzLivenessSDK.setEventsConnection(
    OzConnection.fromCredentials(
        "https://echo.cdn.ozforensics.com/",
        "<your_telemetry_user_eg_tm@company.com>",
        "your_telemetry_password"
    )
)
```

{% endtab %}

{% tab title="Java" %}

```java
OzLivenessSDK.setEventsConnection(
        OzConnection.fromCredentials(
                "https://tm.ozforensics.com/",
                "<your_telemetry_user_eg_tm@company.com>",
                "your_telemetry_password"
        )
);
```

{% endtab %}
{% endtabs %}

Clearing authorization:

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
OzLivenessSDK.setApiConnection(null)
```

{% endtab %}

{% tab title="Java" %}

```java
OzLivenessSDK.INSTANCE.setApiConnection(null, null);
```

{% endtab %}
{% endtabs %}

### Other methods

Check for the presence of the saved Oz API access token:

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
val isLoggedIn = OzLivenessSDK.isLoggedIn
```

{% endtab %}

{% tab title="Java" %}

```java
boolean isLoggedIn = OzLivenessSDK.INSTANCE.isLoggedIn();
```

{% endtab %}
{% endtabs %}

LogOut:

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
OzLivenessSDK.logout()
```

{% endtab %}

{% tab title="Java" %}

```java
OzLivenessSDK.INSTANCE.logout();
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://doc.ozforensics.com/oz-knowledge/guides/developer-guide/sdk/oz-mobile-sdk/android/connecting-sdk-to-api.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
