diff --git a/langsmith-java-example/README.md b/langsmith-java-example/README.md
index 11f072d2..3cc1b105 100644
--- a/langsmith-java-example/README.md
+++ b/langsmith-java-example/README.md
@@ -8,10 +8,15 @@ This module contains runnable examples organized by feature:
All examples require:
```bash
+./gradlew :langsmith-java-example:run -Pexample=ExampleName -Dlangchain.langsmithApiKey=your_api_key
+```
+
+Alternatively, you can use environment variables:
+```bash
export LANGSMITH_API_KEY=your_api_key
```
-The `LANGCHAIN_BASE_URL` environment variable is optional and defaults to `https://api.smith.langchain.com` if not set.
+The `langchain.baseUrl` system property (or `LANGCHAIN_BASE_URL` environment variable) is optional and defaults to `https://api.smith.langchain.com/` if not set.
## OpenTelemetry Tracing Examples
@@ -37,10 +42,10 @@ open http://localhost:16686
Make actual OpenAI API calls with automatic tracing to LangSmith.
```bash
-export OPENAI_API_KEY=your_openai_key
-export LANGSMITH_PROJECT=my-project # optional, defaults to "default"
-
-./gradlew :langsmith-java-example:run -Pexample=OtelOpenAI
+./gradlew :langsmith-java-example:run -Pexample=OtelOpenAI \
+ -Dlangchain.langsmithApiKey=your_api_key \
+ -DOPENAI_API_KEY=your_openai_key \
+ -DLANGSMITH_PROJECT=my-project # optional, defaults to "default"
```
View traces at https://smith.langchain.com
@@ -50,9 +55,9 @@ View traces at https://smith.langchain.com
Send mock traces to LangSmith without external API calls.
```bash
-export LANGSMITH_PROJECT=my-project # optional, defaults to "default"
-
-./gradlew :langsmith-java-example:run -Pexample=OtelLangSmith
+./gradlew :langsmith-java-example:run -Pexample=OtelLangSmith \
+ -Dlangchain.langsmithApiKey=your_api_key \
+ -DLANGSMITH_PROJECT=my-project # optional, defaults to "default"
```
View traces at https://smith.langchain.com
@@ -62,10 +67,10 @@ View traces at https://smith.langchain.com
REST API with OpenTelemetry traces sent to LangSmith.
```bash
-export LANGSMITH_PROJECT=my-project # optional
-
# Start server
-./gradlew :langsmith-java-example:run -Pexample=SpringBootLangSmith
+./gradlew :langsmith-java-example:run -Pexample=SpringBootLangSmith \
+ -Dlangchain.langsmithApiKey=your_api_key \
+ -DLANGSMITH_PROJECT=my-project # optional
# In another terminal, test endpoints:
curl -X POST http://localhost:8080/api/chat \
@@ -84,7 +89,8 @@ Located in `src/main/java/com/langchain/smith/example/prompt/`
**RECOMMENDED** - Clean, simple example following the same pattern as the Dataset example.
```bash
-./gradlew :langsmith-java-example:run -Pexample=PromptManagement
+./gradlew :langsmith-java-example:run -Pexample=PromptManagement \
+ -Dlangchain.langsmithApiKey=your_api_key
```
**Features demonstrated:**
diff --git a/langsmith-java-example/src/main/java/com/langchain/smith/example/prompt/PromptManagementExample.java b/langsmith-java-example/src/main/java/com/langchain/smith/example/prompt/PromptManagementExample.java
deleted file mode 100644
index ceb49c29..00000000
--- a/langsmith-java-example/src/main/java/com/langchain/smith/example/prompt/PromptManagementExample.java
+++ /dev/null
@@ -1,374 +0,0 @@
-package com.langchain.smith.example.prompt;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.langchain.smith.client.LangsmithClient;
-import com.langchain.smith.client.okhttp.LangsmithOkHttpClient;
-import com.langchain.smith.core.JsonValue;
-import com.langchain.smith.models.commits.CommitListParams;
-import com.langchain.smith.models.commits.CommitListResponse;
-import com.langchain.smith.models.commits.CommitManifestResponse;
-import com.langchain.smith.models.commits.CommitRetrieveParams;
-import com.langchain.smith.models.commits.CommitUpdateParams;
-import com.langchain.smith.models.repos.RepoCreateParams;
-import com.langchain.smith.models.repos.RepoListParams;
-import com.langchain.smith.models.repos.RepoListResponse;
-import com.langchain.smith.models.repos.RepoWithLookups;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Demonstrates how to manage prompts programmatically using the LangSmith Java
- * SDK.
- *
- *
- * This example shows:
- * - Creating prompt repositories (repos)
- * - Adding prompt content as commits (with variables)
- * - Listing prompts with filters
- * - Retrieving prompt content
- * - Pulling specific versions
- *
- *
- * Prerequisites:
- * - `LANGSMITH_API_KEY`: Your LangSmith API key
- * - `LANGCHAIN_BASE_URL`: LangSmith API URL (https://api.smith.langchain.com)
- *
- *
- * Running:
- * ```bash
- * ./gradlew :langsmith-java-example:run -Pexample=PromptManagement
- * ```
- */
-public class PromptManagementExample {
-
- private static final ObjectMapper MAPPER = new ObjectMapper();
-
- public static void main(String[] args) {
- System.out.println("=== LangSmith Prompt Management Example ===\n");
-
- LangsmithClient client = LangsmithOkHttpClient.fromEnv();
- String owner = getOwnerFromEnv();
- String promptName = "joke-generator";
-
- try {
- // 1. Check if prompt already exists
- System.out.println("1. Checking for existing prompt using client.repos().list()...");
- RepoWithLookups existing = findPrompt(client, promptName);
- boolean promptExists = existing != null;
-
- if (promptExists) {
- System.out.println(" ℹ Prompt '" + promptName + "' already exists");
- System.out.println(" View: https://smith.langchain.com/prompts/" + existing.fullName());
- System.out.println(" Skipping creation steps...\n");
- } else {
- System.out.println(" ✓ No existing prompt found\n");
-
- // 2. Create prompt repository (metadata only)
- System.out.println("2. Creating prompt repository using client.repos().create()...");
- client.repos()
- .create(RepoCreateParams.builder()
- .repoHandle(promptName)
- .description("A joke generator that accepts a topic variable")
- .isPublic(false)
- .build());
- System.out.println(" ✓ Created prompt repository: " + promptName + "\n");
- }
-
- // 3. Add prompt content as a commit (only if prompt is new or has no commits)
- boolean commitCreated = false;
- if (promptExists) {
- String parentCommitHash = getLatestCommitHash(client, promptName, owner);
- if (parentCommitHash != null) {
- System.out.println("3. Prompt already has content, skipping commit creation...");
- System.out.println(" ℹ To update the prompt, delete it first or modify the content\n");
- } else {
- commitCreated = createCommit(client, promptName, owner, null);
- }
- } else {
- commitCreated = createCommit(client, promptName, owner, null);
- }
-
- // 4. List prompts
- System.out.println("4. Listing prompts using client.repos().list()...");
- RepoListResponse allPrompts = client.repos()
- .list(RepoListParams.builder()
- .isPublic(RepoListParams.IsPublic.FALSE)
- .limit(100L)
- .build());
- System.out.println(" ✓ Found " + allPrompts.repos().size() + " prompt(s) in your organization");
-
- RepoListResponse jokePrompts = client.repos()
- .list(RepoListParams.builder()
- .query("joke")
- .isPublic(RepoListParams.IsPublic.FALSE)
- .limit(100L)
- .build());
- System.out.println(
- " ✓ Found " + jokePrompts.repos().size() + " prompt(s) matching 'joke' in your organization\n");
-
- // 5. Pull prompt content (retrieve latest commit)
- System.out.println("5. Pulling prompt content using client.commits().list() and retrieve()...");
-
- String commitHash = getLatestCommitHash(client, promptName, owner);
- if (commitHash == null) {
- throw new RuntimeException("No commits found for prompt");
- }
-
- System.out.println(" ✓ Latest commit: " + commitHash.substring(0, 8) + "...");
-
- // Retrieve the manifest
- CommitManifestResponse manifestResponse = client.commits()
- .retrieve(
- commitHash,
- CommitRetrieveParams.builder()
- .owner(owner)
- .repo(promptName)
- .build());
-
- String promptContent = extractPromptContent(manifestResponse._manifest());
- System.out.println(" ✓ Prompt content: \"" + promptContent + "\"\n");
-
- // 6. Demonstrate using the prompt with a value
- System.out.println("6. Using the prompt with a value...");
- String filledPrompt = promptContent.replace("{topic}", "dogs");
- System.out.println(" Template: \"" + promptContent + "\"");
- System.out.println(" Filled: \"" + filledPrompt + "\"\n");
-
- // Summary
- System.out.println("=== Summary ===");
- if (!promptExists) {
- System.out.println("✓ Created prompt repository");
- } else {
- System.out.println("ℹ Prompt already existed (skipped creation)");
- }
- if (commitCreated) {
- System.out.println("✓ Added prompt content as commit");
- } else {
- System.out.println("ℹ Prompt content unchanged (skipped commit)");
- }
- System.out.println("✓ Listed and filtered prompts");
- System.out.println("✓ Retrieved prompt content");
- System.out.println("✓ Demonstrated using prompt with a value");
- System.out.println();
- System.out.println("Learn more:");
- System.out.println("https://docs.langchain.com/langsmith/manage-prompts-programmatically");
-
- } catch (Exception e) {
- System.err.println("\nError: " + e.getMessage());
- e.printStackTrace();
- System.exit(1);
- } finally {
- client.close();
- }
- }
-
- /**
- * Creates a chat prompt manifest with multiple messages (system + user) compatible with LangSmith.
- */
- private static Map createChatPromptWithMultipleMessages(
- String systemMessage, String userMessage, String[] inputVariables) {
- Map manifest = new HashMap<>();
- manifest.put("lc", 1);
- manifest.put("type", "constructor");
- manifest.put("id", new String[] {"langchain", "prompts", "chat", "ChatPromptTemplate"});
-
- Map kwargs = new HashMap<>();
- kwargs.put("input_variables", inputVariables);
-
- java.util.List