For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
DocsAPI Reference
  • Fundamentals
    • Home
    • Why Skyflow?
    • Get started with Skyflow
    • Explore what Skyflow can do
    • Authenticate
    • Accounts and environments
    • Deployment models
    • Security best practices
    • Compliance and certifications
    • Get data into Skyflow
    • Platform FAQs
  • Governance
    • Overview
  • Tokenization
    • Overview
  • Connections
    • Overview
  • Processing
  • AI and data sanitization
    • Overview
  • SDKs
    • Overview
      • Go: Migrate from V1 to V2
      • Python: Migrate from V1 to V2
      • Node.js: Migrate from V1 to V2
      • Java: Migrate from V1 to V2
  • Elements
    • Collect and reveal data with Skyflow Elements
LogoLogo
Login
Login
On this page
  • Authentication
  • Initialize the client
  • Insert records
  • Request options
  • Error handling
SDKsOverview

Java SDK: Migrate from V1 to V2

Was this page helpful?
Previous

Collect and reveal data with Skyflow Elements

Next
Built with

This guide outlines the steps required to migrate the Skyflow Java SDK from version 1 (V1) to version 2 (V2).

Authentication

V1 required implementing a TokenProvider interface. V2 lets you choose from five credential types.

V1:

1static class DemoTokenProvider implements TokenProvider {
2 @Override
3 public String getBearerToken() throws Exception {
4 ResponseToken res = null;
5 try {
6 String filePath = "<YOUR_CREDENTIALS_FILE_HERE>";
7 res = Token.generateBearerToken(filePath);
8 } catch (SkyflowException e) {
9 e.printStackTrace();
10 }
11 return res.getAccessToken();
12 }
13}

V2:

1// Option 1: API key (recommended)
2Credentials skyflowCredentials = new Credentials();
3skyflowCredentials.setApiKey("<YOUR_API_KEY>");
4
5// Option 2: Environment variable — set SKYFLOW_CREDENTIALS in your environment
6
7// Option 3: Credentials file
8skyflowCredentials.setPath("<YOUR_CREDENTIALS_FILE_PATH>");
9
10// Option 4: Stringified JSON
11skyflowCredentials.setCredentialsString("<YOUR_CREDENTIALS_STRING>");
12
13// Option 5: Bearer token
14skyflowCredentials.setToken("<BEARER_TOKEN>");

Use only one authentication method. API key or environment variables are recommended for production use.

Initialize the client

V2 introduces a builder pattern and multi-vault support. Log levels are now per-instance instead of global.

V1:

1DemoTokenProvider demoTokenProvider = new DemoTokenProvider();
2SkyflowConfiguration skyflowConfig = new SkyflowConfiguration(
3 "<VAULT_ID>",
4 "<VAULT_URL>",
5 demoTokenProvider
6);
7Skyflow skyflowClient = Skyflow.init(skyflowConfig);

V2:

1Credentials credentials = new Credentials();
2credentials.setPath("<YOUR_CREDENTIALS_FILE_PATH>");
3
4VaultConfig config = new VaultConfig();
5config.setVaultId("<YOUR_VAULT_ID>");
6config.setClusterId("<YOUR_CLUSTER_ID>"); // ID from your vault URL e.g., https://{clusterId}.vault.skyflowapis.com
7config.setEnv(Env.PROD);
8config.setCredentials(credentials);
9
10Credentials skyflowCredentials = new Credentials();
11skyflowCredentials.setPath("<YOUR_CREDENTIALS_FILE_PATH_2>");
12
13Skyflow skyflowClient = Skyflow.builder()
14 .setLogLevel(LogLevel.INFO)
15 .addVaultConfig(config)
16 .addSkyflowCredentials(skyflowCredentials) // Used if no individual vault credentials are set
17 .build();

Key changes:

  • vaultUrl replaced with clusterId
  • env is now required (Env.PROD, Env.SANDBOX, Env.DEV)
  • Log level is set per client instance
  • Builder pattern replaces direct constructor calls

Insert records

V2 uses native ArrayList and HashMap instead of JSON objects from third-party libraries. Requests use a builder pattern.

V1:

1JSONObject recordsJson = new JSONObject();
2JSONArray recordsArrayJson = new JSONArray();
3
4JSONObject recordJson = new JSONObject();
5recordJson.put("table", "cards");
6
7JSONObject fieldsJson = new JSONObject();
8fieldsJson.put("cardNumber", "41111111111");
9fieldsJson.put("cvv", "123");
10
11recordJson.put("fields", fieldsJson);
12recordsArrayJson.add(recordJson);
13recordsJson.put("records", recordsArrayJson);
14
15JSONObject insertResponse = skyflowClient.insert(recordsJson);

V2:

1ArrayList<HashMap<String, Object>> values = new ArrayList<>();
2HashMap<String, Object> value = new HashMap<>();
3value.put("<COLUMN_NAME_1>", "<COLUMN_VALUE_1>");
4value.put("<COLUMN_NAME_2>", "<COLUMN_VALUE_2>");
5values.add(value);
6
7ArrayList<HashMap<String, Object>> tokens = new ArrayList<>();
8HashMap<String, Object> token = new HashMap<>();
9token.put("<COLUMN_NAME_2>", "<TOKEN_VALUE_2>");
10tokens.add(token);
11
12InsertRequest insertRequest = InsertRequest.builder()
13 .table("<TABLE_NAME>")
14 .values(values)
15 .tokens(tokens)
16 .tokenMode(TokenMode.ENABLE)
17 .returnTokens(true)
18 .continueOnError(true)
19 .build();
20
21InsertResponse insertResponse = skyflowClient.vault("<VAULT_ID>").insert(insertRequest);

V1 response:

1{
2 "records": [
3 {
4 "table": "cards",
5 "fields": {
6 "skyflow_id": "16419435-aa63-4823-aae7-19c6a2d6a19f",
7 "cardNumber": "f3907186-e7e2-466f-91e5-48e12c2bcbc1",
8 "cvv": "1989cb56-63da-4482-a2df-1f74cd0dd1a5"
9 }
10 }
11 ]
12}

V2 response:

1{
2 "insertedFields": [
3 {
4 "skyflow_id": "9fac9201-7b8a-4446-93f8-5244e1213bd1",
5 "card_number": "5484-7829-1702-9110",
6 "request_index": "0"
7 }
8 ],
9 "errors": []
10}

Request options

V2 uses the builder pattern on InsertRequest for optional parameters instead of a separate InsertOptions object.

V1:

1InsertOptions insertOptions = new InsertOptions(true);

V2:

1InsertRequest insertRequest = InsertRequest.builder()
2 .table("<TABLE_NAME>")
3 .values(values)
4 .continueOnError(false)
5 .tokenMode(TokenMode.DISABLE)
6 .returnTokens(false)
7 .upsert("<UPSERT_COLUMN>")
8 .build();

Error handling

V2 errors include more detail to help with debugging.

V1:

1{
2 "code": "<http_code>",
3 "description": "<description>"
4}

V2:

1{
2 "httpStatus": "<http_status>",
3 "grpcCode": "<grpc_code>",
4 "httpCode": "<http_code>",
5 "message": "<message>",
6 "requestId": "<request_id>",
7 "details": ["<details>"]
8}

Use the requestId field when contacting Skyflow support — it uniquely identifies the request for faster diagnosis.