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

# Getting SDK Connection Details

To retrieve your SDK connection details ensure you have first:

1. Created A Ditto Portal Account - [Creating a Ditto Account](https://docs.ditto.live/cloud/portal/creating-a-ditto-account.md)
2. Created A Ditto Database - [Creating a New Database](https://docs.ditto.live/cloud/portal/creating-a-new-app.md)

After you've created your database, select it from the list.

On the `Connect` tab, you will see the following details under `Big peer connection information`:

* Database ID - The unique identifier for your database.
* Auth URL - This is the URL you will need to pass to your SDK to authenticate.
* Websocket URL - This is the URL you will need to pass to your SDK to initiate replication via Websocket to Ditto Server.

On the `Connect` tab, under `Authentication Mode`, if you are still using the default authentication settings, you will also see the `Online Playground Authentication Token`.
This token is used to authenticate your SDK to Ditto Server. It allows you to explore Ditto platform features and functionality without the hassle of setting up your own authentication mechanism.

## Offline License Tokens

Offline license tokens allow your application to operate without connectivity to a Ditto Server (Big Peer) deployment, including Ditto's cloud. They are generally issued by Ditto personnel to customers with a production agreement. If you're interested, please [contact us](https://support.ditto.com) or chat to our support team.

When issued, offline license tokens are available on the **Connect** tab for your database in the Portal.

Offline license tokens have an expiration period. The default expiration is 30 days, but you can customize this when creating a new token.

### Required Permissions

To view offline license tokens, your Portal role must include the **Access offline-only licenses** permission. To create or manage offline license tokens, your role must also include the **Request offline-only licenses** permission.

For details on configuring roles, see [Role-Based Access Control](https://docs.ditto.live/cloud/portal/role-based-access-control.md).

> [!TIP]
>
> If you do not see the offline license token section on the Connect tab, your role may not have the required permissions. Contact your organization admin to request the **Access offline-only licenses** and/or **Request offline-only licenses** permissions, or reach out to [Ditto support](https://docs.ditto.live/support) to have tokens generated on your behalf.

## Connecting an SDK

Below are some examples of how to connect an SDK to Ditto Server:

```swift Swift theme={null}
import DittoSwift
import Foundation // v5 no longer re-exports Foundation; needed for URL

// Create a DittoConfig with your database ID.
// Copy the "URL" and "Database ID" from the Ditto Portal (Connect via SDK).
let config = DittoConfig(
    databaseID: "REPLACE_ME_WITH_YOUR_DATABASE_ID",
    connect: .server(url: URL(string: "REPLACE_ME_WITH_YOUR_URL")!)
)

// Open Ditto with the configuration
let ditto = try await Ditto.open(config: config)

// Set up authentication expiration handler
ditto.auth?.expirationHandler = { ditto, secondsRemaining in
    ditto.auth?.login(token: "YOUR_PLAYGROUND_TOKEN", provider: .development) { clientInfo, error in
        if let error = error {
            print("Authentication error: \(error)")
        } else {
            print("Authentication successful")
        }
    }
}

// Start syncing
do {
    try ditto.sync.start()
} catch {
    print("Error starting sync: \(error.localizedDescription)")
}
```

```kotlin Kotlin theme={null}
val config = DittoConfig(
    databaseId = "REPLACE_ME_WITH_YOUR_DATABASE_ID",
    connect = DittoConfig.Connect.Server(url = "REPLACE_ME_WITH_YOUR_URL")
)
val ditto = DittoFactory.create(config)

// Auth is null when using Connect.SmallPeersOnly — guard with `?.let { }`.
ditto.auth?.let { auth ->
    auth.expirationHandler = { ditto, timeUntilExpiration ->
        // This lambda is suspend — call login() directly, no separate coroutine.
        ditto.auth?.login(
            token = "YOUR_PLAYGROUND_TOKEN",
            provider = DittoAuthenticationProvider.development(),
        )
    }
}

ditto.sync.start()
```

```dart Dart theme={null}
import 'package:ditto_live/ditto_live.dart';

await Ditto.init();

// Copy the "URL" and "Database ID" from the Ditto Portal (Connect via SDK).
final config = DittoConfig(
  databaseID: 'REPLACE_ME_WITH_YOUR_DATABASE_ID',
  connect: DittoConfigConnectServer(
    url: 'REPLACE_ME_WITH_YOUR_URL',
  ),
);

final ditto = await Ditto.open(config);

await ditto.auth.setExpirationHandler((ditto, timeUntilExpiration) async {
  final result = await ditto.auth.login(
    token: 'REPLACE_ME_WITH_YOUR_PLAYGROUND_TOKEN',
    provider: Authenticator.developmentProvider,
  );
  if (result.exception != null) {
    print('Auth error: ${result.exception}');
  }
});

ditto.sync.start();
```

```javascript JavaScript theme={null}
import { init, Ditto, DittoConfig, Authenticator } from '@dittolive/ditto'

await init()

const databaseID = 'REPLACE_ME_WITH_YOUR_DATABASE_ID'
// Copy the "URL" and "Database ID" from the Ditto Portal (Connect via SDK).
const config = new DittoConfig(databaseID, {
  mode: 'server',
  url: 'REPLACE_ME_WITH_YOUR_URL'
})

const ditto = await Ditto.open(config)

await ditto.auth.setExpirationHandler(async (ditto, secondsRemaining) => {
  console.log('Token expiring in:', secondsRemaining)
  const result = await ditto.auth.login('REPLACE_ME_WITH_YOUR_PLAYGROUND_TOKEN', Authenticator.DEVELOPMENT_PROVIDER)
  if (result.error) {
    console.error('Auth error:', result.error)
  }
})

ditto.sync.start()
```

```typescript TypeScript theme={null}
import { init, Ditto, DittoConfig, Authenticator } from '@dittolive/ditto'

await init()

const databaseID: string = 'REPLACE_ME_WITH_YOUR_DATABASE_ID'
// Copy the "URL" and "Database ID" from the Ditto Portal (Connect via SDK).
const config = new DittoConfig(databaseID, {
  mode: 'server',
  url: 'REPLACE_ME_WITH_YOUR_URL'
})

const ditto: Ditto = await Ditto.open(config)

await ditto.auth.setExpirationHandler(async (ditto: Ditto, secondsRemaining: number) => {
  console.log('Token expiring in:', secondsRemaining)
  const result = await ditto.auth.login('REPLACE_ME_WITH_YOUR_PLAYGROUND_TOKEN', Authenticator.DEVELOPMENT_PROVIDER)
  if (result.error) {
    console.error('Auth error:', result.error)
  }
})

ditto.sync.start()
```

```java Java theme={null}
import com.ditto.java.Ditto;
import com.ditto.java.DittoAuthenticationProvider;
import com.ditto.java.DittoConfig;
import com.ditto.java.DittoException;
import com.ditto.java.DittoFactory;

// Your HTTP Cloud URL Endpoint
String endpoint = "REPLACE_ME_WITH_YOUR_URL";
String databaseId = "REPLACE_ME_WITH_YOUR_DATABASE_ID";

DittoConfig config = new DittoConfig.Builder(databaseId)
    .connect(new DittoConfig.Connect.Server(endpoint))
    .build();

try {
    Ditto ditto = DittoFactory.create(config);

    // Set up authentication expiration handler (required for server connections).
    // The handler returns a CompletionStage<Void>.
    ditto.getAuth().setExpirationHandler((expiringDitto, timeUntilExpiration) ->
        expiringDitto.getAuth().login(
            "REPLACE_ME_WITH_YOUR_DEVELOPMENT_TOKEN",
            DittoAuthenticationProvider.development()
        ).thenAccept(result -> {
            if (result.error() != null) {
                System.out.println("Authentication failed: " + result.error());
            } else {
                System.out.println("Authentication successful");
            }
        })
    );

    // Start sync (v5 pattern: ditto.getSync().start())
    ditto.getSync().start();
} catch (DittoException e) {
    System.out.println("Ditto initialization failed: " + e.getMessage());
}
```

```csharp C# theme={null}
using DittoSDK;

// Copy the "URL" and "Database ID" from the Ditto Portal (Connect via SDK).
var databaseId = "REPLACE_ME_WITH_YOUR_DATABASE_ID";
var config = new DittoConfig(
    databaseId: databaseId,
    connect: new DittoConfigConnect.Server(new Uri("REPLACE_ME_WITH_YOUR_URL"))
);

var ditto = await Ditto.OpenAsync(config);

ditto.Auth.ExpirationHandler = async (ditto, secondsRemaining) => {
    try
    {
        var result = await ditto.Auth.LoginAsync("YOUR_PLAYGROUND_TOKEN", DittoAuthenticationProvider.Development);
    }
    catch (Exception e)
    {
        Console.WriteLine($"Authentication failed: {e}");
    }
};

ditto.Sync.Start();
```

```cpp C++ theme={null}
#include <ditto/ditto.h>

// Copy the "URL" and "Database ID" from the Ditto Portal (Connect via SDK).
auto database_id = "REPLACE_ME_WITH_YOUR_DATABASE_ID";
auto config = ditto::DittoConfig(
    database_id,
    ditto::DittoConnect::server("REPLACE_ME_WITH_YOUR_URL")
);

auto ditto = ditto::Ditto::open(config);

ditto->auth()->set_expiration_handler([](ditto::Ditto& ditto, int64_t seconds_remaining) {
    ditto.auth()->login("YOUR_PLAYGROUND_TOKEN", ditto::Authenticator::development_provider(),
        [](const ditto::AuthenticationSuccess* success, const ditto::DittoError* error) {
            if (error) {
                std::cerr << "Auth error" << std::endl;
            }
        });
});

ditto->update_transport_config([&](ditto::TransportConfig &config) {
    config.enable_all_peer_to_peer();
});

ditto->get_sync()->start();
```

```rust Rust theme={null}
use dittolive_ditto::prelude::*;
use std::time::Duration;

// Initialize with DittoConfig using database_id (was app_id in v4).
// Copy the "URL" and "Database ID" from the Ditto Portal (Connect via SDK).
let database_id = DatabaseId::from_str("REPLACE_ME_WITH_YOUR_DATABASE_ID")?;
let config = DittoConfig::new(
    database_id.clone(),
    DittoConnect::Server {
        url: "REPLACE_ME_WITH_YOUR_URL".to_string()
    }
);

let ditto = Ditto::open(config)?;

// Set up authentication expiration handler
ditto.auth().set_expiration_handler(|ditto, seconds_remaining| {
    ditto.auth().login(
        "REPLACE_ME_WITH_YOUR_PLAYGROUND_TOKEN",
        Authenticator::development_provider(),
        |result| {
            if let Err(e) = result {
                eprintln!("Auth error: {}", e);
            }
        }
    );
});

// Configure transport (optional)
ditto.set_transport_config({
    let mut config = TransportConfig::new();
    config
        .connect
        .websocket_urls
        // Your Portal URL with the scheme changed from https:// to wss:// (host only)
        .insert("wss://REPLACE_ME_WITH_YOUR_URL_HOST".to_string());
    config
});

// Start sync (was ditto.start_sync() in v4)
ditto.sync().start()?;
```

```go Go theme={null}
const endpoint = "REPLACE_ME_WITH_YOUR_URL"
const id       = "REPLACE_ME_WITH_YOUR_DATABASE_ID"
const token    = "REPLACE_ME_WITH_YOUR_DEVELOPMENT_TOKEN"

config := ditto.DefaultDittoConfig().
    WithDatabaseID(id).
    WithConnect(&ditto.DittoConfigConnectServer{URL: endpoint})

dit, err := ditto.Open(config)
if err != nil {
    log.Fatalf("error: failed to open Ditto: %v", err)
}
defer dit.Close()

// Set up authentication expiration handler (required for server connections)
dit.Auth().SetExpirationHandler(
    func(d *ditto.Ditto, timeUntilExpiration time.Duration) {
        _, err := d.Auth().Login(token, ditto.DevelopmentAuthenticationProvider())
        if err != nil {
            log.Errorf("Authentication failed: %v", err)
        } else {
            log.Printf("Authentication succeeded")
        }
    })

if err := dit.Sync().Start(); err != nil {
    log.Errorf("error: failed to start sync: %v", err)
}
```


## Related topics

- [C++ Console App Quickstart](https://docs.ditto.live/sdk/latest/quickstarts/cpp-console.md)
- [.NET (C#) MAUI Quickstart](https://docs.ditto.live/sdk/latest/quickstarts/dotnet-maui.md)
- [.NET (C#) Console App Quickstart](https://docs.ditto.live/sdk/latest/quickstarts/dotnet-console.md)
