{"id":15442375,"url":"https://github.com/langchain-ai/langsmith-java","last_synced_at":"2026-04-02T13:31:33.617Z","repository":{"id":325335998,"uuid":"774515765","full_name":"langchain-ai/langsmith-java","owner":"langchain-ai","description":"LangSmith Java SDK.","archived":false,"fork":false,"pushed_at":"2026-03-30T20:14:24.000Z","size":32873,"stargazers_count":14,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2026-03-30T21:25:48.934Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/langchain-ai.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2024-03-19T17:23:58.000Z","updated_at":"2026-03-28T04:11:35.000Z","dependencies_parsed_at":"2026-03-05T20:03:09.078Z","dependency_job_id":null,"html_url":"https://github.com/langchain-ai/langsmith-java","commit_stats":null,"previous_names":["langchain-ai/langsmith-java"],"tags_count":46,"template":false,"template_full_name":null,"purl":"pkg:github/langchain-ai/langsmith-java","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/langchain-ai%2Flangsmith-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/langchain-ai%2Flangsmith-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/langchain-ai%2Flangsmith-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/langchain-ai%2Flangsmith-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/langchain-ai","download_url":"https://codeload.github.com/langchain-ai/langsmith-java/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/langchain-ai%2Flangsmith-java/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31307132,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-02T12:59:32.332Z","status":"ssl_error","status_checked_at":"2026-04-02T12:54:48.875Z","response_time":89,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T19:27:08.687Z","updated_at":"2026-04-02T13:31:33.610Z","avatar_url":"https://github.com/langchain-ai.png","language":"Kotlin","funding_links":[],"categories":["人工智能"],"sub_categories":["LLMOps"],"readme":"# LangSmith Java SDK\n\n\u003c!-- x-release-please-start-version --\u003e\n\n[![Maven Central](https://img.shields.io/maven-central/v/com.langchain.smith/langsmith-java)](https://central.sonatype.com/artifact/com.langchain.smith/langsmith-java/0.1.0-alpha.25)\n[![javadoc](https://javadoc.io/badge2/com.langchain.smith/langsmith-java/0.1.0-alpha.25/javadoc.svg)](https://javadoc.io/doc/com.langchain.smith/langsmith-java/0.1.0-alpha.25)\n\n\u003c!-- x-release-please-end --\u003e\n\nThe [LangSmith](https://www.langchain.com/langsmith/observability) Java SDK provides convenient access to the LangSmith [REST API](https://api.smith.langchain.com/docs) from applications written in Java.\n\nTo learn more about LangSmith, check out the [docs](https://docs.smith.langchain.com/).\n\n\u003c!-- x-release-please-start-version --\u003e\n\nThe REST API documentation can be found on [docs.smith.langchain.com](https://docs.smith.langchain.com/). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.langchain.smith/langsmith-java/0.1.0-alpha.25).\n\n\u003c!-- x-release-please-end --\u003e\n\n## Installation\n\n\u003c!-- x-release-please-start-version --\u003e\n\n### Gradle\n\n```kotlin\nimplementation(\"com.langchain.smith:langsmith-java:0.1.0-alpha.25\")\n```\n\n### Maven\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.langchain.smith\u003c/groupId\u003e\n  \u003cartifactId\u003elangsmith-java\u003c/artifactId\u003e\n  \u003cversion\u003e0.1.0-alpha.25\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n\u003c!-- x-release-please-end --\u003e\n\n## Requirements\n\nThis library requires Java 8 or later.\n\n## Usage\n\n```java\nimport com.langchain.smith.client.LangsmithClient;\nimport com.langchain.smith.client.okhttp.LangsmithOkHttpClient;\nimport com.langchain.smith.models.runs.RunQueryParams;\n\n// Configures using the `langchain.langsmithApiKey`, `langchain.langsmithTenantId`, `langchain.langsmithBearerToken`, `langchain.langsmithOrganizationId` and `langchain.baseUrl` system properties\n// Or configures using the `LANGSMITH_API_KEY`, `LANGSMITH_TENANT_ID`, `LANGSMITH_BEARER_TOKEN`, `LANGSMITH_ORGANIZATION_ID` and `LANGSMITH_ENDPOINT` environment variables\nLangsmithClient client = LangsmithOkHttpClient.fromEnv();\n\nRunQueryParams params = RunQueryParams.builder()\n    .addSession(\"1ffaeba7-541e-469f-bae7-df3208ea3d45\")\n    .limit(10L)\n    .build();\nvar response = client.runs().query(params);\n\n// Print runs\nSystem.out.println(\"Found \" + response.runs().size() + \" runs:\");\nfor (var run : response.runs()) {\n    System.out.println(\"Run ID: \" + run.id());\n    System.out.println(\"Run Name: \" + run.name());\n    System.out.println(\"---\");\n}\n```\n\n## Examples\n\nThis repository includes runnable examples in the `langsmith-java-example` module to help you get started.\n\n### Running Examples\n\nExamples can be run using Gradle:\n\n```bash\n# Set required environment variables\nexport LANGSMITH_API_KEY=\"your-api-key\"\nexport LANGSMITH_ENDPOINT=\"https://api.smith.langchain.com\"\n\n# Run a specific example\n./gradlew :langsmith-java-example:run -Pexample=ListRuns\n```\n\n### Available Examples\n\n```bash\nexport LANGSMITH_PROJECT_ID=\"your-project-id\"\n./gradlew :langsmith-java-example:run -Pexample=ListRuns\n```\n\nAll examples are available in [`langsmith-java-example`](langsmith-java-example).\n\n## Client configuration\n\nConfigure the client using system properties or environment variables:\n\n```java\nimport com.langchain.smith.client.LangsmithClient;\nimport com.langchain.smith.client.okhttp.LangsmithOkHttpClient;\n\n// Configures using the `langchain.langsmithApiKey`, `langchain.langsmithTenantId`, `langchain.langsmithBearerToken`, `langchain.langsmithOrganizationId` and `langchain.baseUrl` system properties\n// Or configures using the `LANGSMITH_API_KEY`, `LANGSMITH_TENANT_ID`, `LANGSMITH_BEARER_TOKEN`, `LANGSMITH_ORGANIZATION_ID` and `LANGSMITH_ENDPOINT` environment variables\nLangsmithClient client = LangsmithOkHttpClient.fromEnv();\n```\n\nOr manually:\n\n```java\nimport com.langchain.smith.client.LangsmithClient;\nimport com.langchain.smith.client.okhttp.LangsmithOkHttpClient;\n\nLangsmithClient client = LangsmithOkHttpClient.builder()\n    .apiKey(\"My API Key\")\n    .tenantId(\"My Tenant ID\")\n    .organizationId(\"My Organization ID\")\n    .build();\n```\n\nOr using a combination of the two approaches:\n\n```java\nimport com.langchain.smith.client.LangsmithClient;\nimport com.langchain.smith.client.okhttp.LangsmithOkHttpClient;\n\nLangsmithClient client = LangsmithOkHttpClient.builder()\n    // Configures using the `langchain.langsmithApiKey`, `langchain.langsmithTenantId`, `langchain.langsmithBearerToken`, `langchain.langsmithOrganizationId` and `langchain.baseUrl` system properties\n    // Or configures using the `LANGSMITH_API_KEY`, `LANGSMITH_TENANT_ID`, `LANGSMITH_BEARER_TOKEN`, `LANGSMITH_ORGANIZATION_ID` and `LANGSMITH_ENDPOINT` environment variables\n    .fromEnv()\n    .apiKey(\"My API Key\")\n    .build();\n```\n\nSee this table for the available options:\n\n| Setter           | System property                     | Environment variable        | Required | Default value                        |\n| ---------------- | ----------------------------------- | --------------------------- | -------- | ------------------------------------ |\n| `apiKey`         | `langchain.langsmithApiKey`         | `LANGSMITH_API_KEY`         | false    | -                                    |\n| `tenantId`       | `langchain.langsmithTenantId`       | `LANGSMITH_TENANT_ID`       | false    | -                                    |\n| `bearerToken`    | `langchain.langsmithBearerToken`    | `LANGSMITH_BEARER_TOKEN`    | false    | -                                    |\n| `organizationId` | `langchain.langsmithOrganizationId` | `LANGSMITH_ORGANIZATION_ID` | false    | -                                    |\n| `baseUrl`        | `langchain.baseUrl`                 | `LANGSMITH_ENDPOINT`        | true     | `\"https://api.smith.langchain.com/\"` |\n\nSystem properties take precedence over environment variables.\n\n\u003e [!TIP]\n\u003e Don't create more than one client in the same application. Each client has a connection pool and\n\u003e thread pools, which are more efficient to share between requests.\n\n### Modifying configuration\n\nTo temporarily use a modified client configuration, while reusing the same connection and thread pools, call `withOptions()` on any client or service:\n\n```java\nimport com.langchain.smith.client.LangsmithClient;\n\nLangsmithClient clientWithOptions = client.withOptions(optionsBuilder -\u003e {\n    optionsBuilder.baseUrl(\"https://example.com\");\n    optionsBuilder.maxRetries(42);\n});\n```\n\nThe `withOptions()` method does not affect the original client or service.\n\n## Requests and responses\n\nTo send a request to the LangChain API, build an instance of some `Params` class and pass it to the corresponding client method. When the response is received, it will be deserialized into an instance of a Java class.\n\nFor example, `client.sessions().dashboard(...)` should be called with an instance of `SessionDashboardParams`, and it will return an instance of `CustomChartsSection`.\n\n## Immutability\n\nEach class in the SDK has an associated [builder](https://blogs.oracle.com/javamagazine/post/exploring-joshua-blochs-builder-design-pattern-in-java) or factory method for constructing it.\n\nEach class is [immutable](https://docs.oracle.com/javase/tutorial/essential/concurrency/immutable.html) once constructed. If the class has an associated builder, then it has a `toBuilder()` method, which can be used to convert it back to a builder for making a modified copy.\n\nBecause each class is immutable, builder modification will _never_ affect already built class instances.\n\n## Asynchronous execution\n\nThe default client is synchronous. To switch to asynchronous execution, call the `async()` method:\n\n```java\nimport com.langchain.smith.client.LangsmithClient;\nimport com.langchain.smith.client.okhttp.LangsmithOkHttpClient;\nimport com.langchain.smith.models.sessions.CustomChartsSection;\nimport com.langchain.smith.models.sessions.CustomChartsSectionRequest;\nimport com.langchain.smith.models.sessions.SessionDashboardParams;\nimport java.util.concurrent.CompletableFuture;\n\n// Configures using the `langchain.langsmithApiKey`, `langchain.langsmithTenantId`, `langchain.langsmithBearerToken`, `langchain.langsmithOrganizationId` and `langchain.baseUrl` system properties\n// Or configures using the `LANGSMITH_API_KEY`, `LANGSMITH_TENANT_ID`, `LANGSMITH_BEARER_TOKEN`, `LANGSMITH_ORGANIZATION_ID` and `LANGSMITH_ENDPOINT` environment variables\nLangsmithClient client = LangsmithOkHttpClient.fromEnv();\n\nSessionDashboardParams params = SessionDashboardParams.builder()\n    .sessionId(\"1ffaeba7-541e-469f-bae7-df3208ea3d45\")\n    .customChartsSectionRequest(CustomChartsSectionRequest.builder().build())\n    .build();\nCompletableFuture\u003cCustomChartsSection\u003e customChartsSection = client.async().sessions().dashboard(params);\n```\n\nOr create an asynchronous client from the beginning:\n\n```java\nimport com.langchain.smith.client.LangsmithClientAsync;\nimport com.langchain.smith.client.okhttp.LangsmithOkHttpClientAsync;\nimport com.langchain.smith.models.sessions.CustomChartsSection;\nimport com.langchain.smith.models.sessions.CustomChartsSectionRequest;\nimport com.langchain.smith.models.sessions.SessionDashboardParams;\nimport java.util.concurrent.CompletableFuture;\n\n// Configures using the `langchain.langsmithApiKey`, `langchain.langsmithTenantId`, `langchain.langsmithBearerToken`, `langchain.langsmithOrganizationId` and `langchain.baseUrl` system properties\n// Or configures using the `LANGSMITH_API_KEY`, `LANGSMITH_TENANT_ID`, `LANGSMITH_BEARER_TOKEN`, `LANGSMITH_ORGANIZATION_ID` and `LANGSMITH_ENDPOINT` environment variables\nLangsmithClientAsync client = LangsmithOkHttpClientAsync.fromEnv();\n\nSessionDashboardParams params = SessionDashboardParams.builder()\n    .sessionId(\"1ffaeba7-541e-469f-bae7-df3208ea3d45\")\n    .customChartsSectionRequest(CustomChartsSectionRequest.builder().build())\n    .build();\nCompletableFuture\u003cCustomChartsSection\u003e customChartsSection = client.sessions().dashboard(params);\n```\n\nThe asynchronous client supports the same options as the synchronous one, except most methods return `CompletableFuture`s.\n\n## File uploads\n\nThe SDK defines methods that accept files.\n\nTo upload a file, pass a [`Path`](https://docs.oracle.com/javase/8/docs/api/java/nio/file/Path.html):\n\n```java\nimport com.langchain.smith.models.examples.Example;\nimport com.langchain.smith.models.examples.ExampleUploadFromCsvParams;\nimport java.nio.file.Paths;\n\nExampleUploadFromCsvParams params = ExampleUploadFromCsvParams.builder()\n    .datasetId(\"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e\")\n    .addInputKey(\"string\")\n    .file(Paths.get(\"/path/to/file\"))\n    .build();\nList\u003cExample\u003e examples = client.examples().uploadFromCsv(params);\n```\n\nOr an arbitrary [`InputStream`](https://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html):\n\n```java\nimport com.langchain.smith.models.examples.Example;\nimport com.langchain.smith.models.examples.ExampleUploadFromCsvParams;\nimport java.net.URL;\n\nExampleUploadFromCsvParams params = ExampleUploadFromCsvParams.builder()\n    .datasetId(\"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e\")\n    .addInputKey(\"string\")\n    .file(new URL(\"https://example.com//path/to/file\").openStream())\n    .build();\nList\u003cExample\u003e examples = client.examples().uploadFromCsv(params);\n```\n\nOr a `byte[]` array:\n\n```java\nimport com.langchain.smith.models.examples.Example;\nimport com.langchain.smith.models.examples.ExampleUploadFromCsvParams;\n\nExampleUploadFromCsvParams params = ExampleUploadFromCsvParams.builder()\n    .datasetId(\"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e\")\n    .addInputKey(\"string\")\n    .file(\"content\".getBytes())\n    .build();\nList\u003cExample\u003e examples = client.examples().uploadFromCsv(params);\n```\n\nNote that when passing a non-`Path` its filename is unknown so it will not be included in the request. To manually set a filename, pass a [`MultipartField`](langsmith-java-core/src/main/kotlin/com/langchain/smith/core/Values.kt):\n\n```java\nimport com.langchain.smith.core.MultipartField;\nimport com.langchain.smith.models.examples.Example;\nimport com.langchain.smith.models.examples.ExampleUploadFromCsvParams;\nimport java.io.InputStream;\nimport java.net.URL;\n\nExampleUploadFromCsvParams params = ExampleUploadFromCsvParams.builder()\n    .datasetId(\"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e\")\n    .addInputKey(\"string\")\n    .file(MultipartField.\u003cInputStream\u003ebuilder()\n        .value(new URL(\"https://example.com//path/to/file\").openStream())\n        .filename(\"/path/to/file\")\n        .build())\n    .build();\nList\u003cExample\u003e examples = client.examples().uploadFromCsv(params);\n```\n\n## Raw responses\n\nThe SDK defines methods that deserialize responses into instances of Java classes. However, these methods don't provide access to the response headers, status code, or the raw response body.\n\nTo access this data, prefix any HTTP method call on a client or service with `withRawResponse()`:\n\n```java\nimport com.langchain.smith.core.http.Headers;\nimport com.langchain.smith.core.http.HttpResponseFor;\nimport com.langchain.smith.models.sessions.CustomChartsSection;\nimport com.langchain.smith.models.sessions.CustomChartsSectionRequest;\nimport com.langchain.smith.models.sessions.SessionDashboardParams;\n\nSessionDashboardParams params = SessionDashboardParams.builder()\n    .sessionId(\"1ffaeba7-541e-469f-bae7-df3208ea3d45\")\n    .customChartsSectionRequest(CustomChartsSectionRequest.builder().build())\n    .build();\nHttpResponseFor\u003cCustomChartsSection\u003e customChartsSection = client.sessions().withRawResponse().dashboard(params);\n\nint statusCode = customChartsSection.statusCode();\nHeaders headers = customChartsSection.headers();\n```\n\nYou can still deserialize the response into an instance of a Java class if needed:\n\n```java\nimport com.langchain.smith.models.sessions.CustomChartsSection;\n\nCustomChartsSection parsedCustomChartsSection = customChartsSection.parse();\n```\n\n## Error handling\n\nThe SDK throws custom unchecked exception types:\n\n- [`LangChainServiceException`](langsmith-java-core/src/main/kotlin/com/langchain/smith/errors/LangChainServiceException.kt): Base class for HTTP errors. See this table for which exception subclass is thrown for each HTTP status code:\n\n  | Status | Exception                                                                                                                          |\n  | ------ | ---------------------------------------------------------------------------------------------------------------------------------- |\n  | 400    | [`BadRequestException`](langsmith-java-core/src/main/kotlin/com/langchain/smith/errors/BadRequestException.kt)                     |\n  | 401    | [`UnauthorizedException`](langsmith-java-core/src/main/kotlin/com/langchain/smith/errors/UnauthorizedException.kt)                 |\n  | 403    | [`PermissionDeniedException`](langsmith-java-core/src/main/kotlin/com/langchain/smith/errors/PermissionDeniedException.kt)         |\n  | 404    | [`NotFoundException`](langsmith-java-core/src/main/kotlin/com/langchain/smith/errors/NotFoundException.kt)                         |\n  | 422    | [`UnprocessableEntityException`](langsmith-java-core/src/main/kotlin/com/langchain/smith/errors/UnprocessableEntityException.kt)   |\n  | 429    | [`RateLimitException`](langsmith-java-core/src/main/kotlin/com/langchain/smith/errors/RateLimitException.kt)                       |\n  | 5xx    | [`InternalServerException`](langsmith-java-core/src/main/kotlin/com/langchain/smith/errors/InternalServerException.kt)             |\n  | others | [`UnexpectedStatusCodeException`](langsmith-java-core/src/main/kotlin/com/langchain/smith/errors/UnexpectedStatusCodeException.kt) |\n\n- [`LangChainIoException`](langsmith-java-core/src/main/kotlin/com/langchain/smith/errors/LangChainIoException.kt): I/O networking errors.\n\n- [`LangChainRetryableException`](langsmith-java-core/src/main/kotlin/com/langchain/smith/errors/LangChainRetryableException.kt): Generic error indicating a failure that could be retried by the client.\n\n- [`LangChainInvalidDataException`](langsmith-java-core/src/main/kotlin/com/langchain/smith/errors/LangChainInvalidDataException.kt): Failure to interpret successfully parsed data. For example, when accessing a property that's supposed to be required, but the API unexpectedly omitted it from the response.\n\n- [`LangChainException`](langsmith-java-core/src/main/kotlin/com/langchain/smith/errors/LangChainException.kt): Base class for all exceptions. Most errors will result in one of the previously mentioned ones, but completely generic errors may be thrown using the base class.\n\n## Pagination\n\nThe SDK defines methods that return a paginated lists of results. It provides convenient ways to access the results either one page at a time or item-by-item across all pages.\n\n### Auto-pagination\n\nTo iterate through all results across all pages, use the `autoPager()` method, which automatically fetches more pages as needed.\n\nWhen using the synchronous client, the method returns an [`Iterable`](https://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html)\n\n```java\nimport com.langchain.smith.models.datasets.Dataset;\nimport com.langchain.smith.models.datasets.DatasetListPage;\n\nDatasetListPage page = client.datasets().list();\n\n// Process as an Iterable\nfor (Dataset dataset : page.autoPager()) {\n    System.out.println(dataset);\n}\n\n// Process as a Stream\npage.autoPager()\n    .stream()\n    .limit(50)\n    .forEach(dataset -\u003e System.out.println(dataset));\n```\n\nWhen using the asynchronous client, the method returns an [`AsyncStreamResponse`](langsmith-java-core/src/main/kotlin/com/langchain/smith/core/http/AsyncStreamResponse.kt):\n\n```java\nimport com.langchain.smith.core.http.AsyncStreamResponse;\nimport com.langchain.smith.models.datasets.Dataset;\nimport com.langchain.smith.models.datasets.DatasetListPageAsync;\nimport java.util.Optional;\nimport java.util.concurrent.CompletableFuture;\n\nCompletableFuture\u003cDatasetListPageAsync\u003e pageFuture = client.async().datasets().list();\n\npageFuture.thenRun(page -\u003e page.autoPager().subscribe(dataset -\u003e {\n    System.out.println(dataset);\n}));\n\n// If you need to handle errors or completion of the stream\npageFuture.thenRun(page -\u003e page.autoPager().subscribe(new AsyncStreamResponse.Handler\u003c\u003e() {\n    @Override\n    public void onNext(Dataset dataset) {\n        System.out.println(dataset);\n    }\n\n    @Override\n    public void onComplete(Optional\u003cThrowable\u003e error) {\n        if (error.isPresent()) {\n            System.out.println(\"Something went wrong!\");\n            throw new RuntimeException(error.get());\n        } else {\n            System.out.println(\"No more!\");\n        }\n    }\n}));\n\n// Or use futures\npageFuture.thenRun(page -\u003e page.autoPager()\n    .subscribe(dataset -\u003e {\n        System.out.println(dataset);\n    })\n    .onCompleteFuture()\n    .whenComplete((unused, error) -\u003e {\n        if (error != null) {\n            System.out.println(\"Something went wrong!\");\n            throw new RuntimeException(error);\n        } else {\n            System.out.println(\"No more!\");\n        }\n    }));\n```\n\n### Manual pagination\n\nTo access individual page items and manually request the next page, use the `items()`,\n`hasNextPage()`, and `nextPage()` methods:\n\n```java\nimport com.langchain.smith.models.datasets.Dataset;\nimport com.langchain.smith.models.datasets.DatasetListPage;\n\nDatasetListPage page = client.datasets().list();\nwhile (true) {\n    for (Dataset dataset : page.items()) {\n        System.out.println(dataset);\n    }\n\n    if (!page.hasNextPage()) {\n        break;\n    }\n\n    page = page.nextPage();\n}\n```\n\n## Logging\n\nThe SDK uses the standard [OkHttp logging interceptor](https://github.com/square/okhttp/tree/master/okhttp-logging-interceptor).\n\nEnable logging by setting the `LANGCHAIN_LOG` environment variable to `info`:\n\n```sh\nexport LANGCHAIN_LOG=info\n```\n\nOr to `debug` for more verbose logging:\n\n```sh\nexport LANGCHAIN_LOG=debug\n```\n\n## ProGuard and R8\n\nAlthough the SDK uses reflection, it is still usable with [ProGuard](https://github.com/Guardsquare/proguard) and [R8](https://developer.android.com/topic/performance/app-optimization/enable-app-optimization) because `langsmith-java-core` is published with a [configuration file](langsmith-java-core/src/main/resources/META-INF/proguard/langsmith-java-core.pro) containing [keep rules](https://www.guardsquare.com/manual/configuration/usage).\n\nProGuard and R8 should automatically detect and use the published rules, but you can also manually copy the keep rules if necessary.\n\n## Jackson\n\nThe SDK depends on [Jackson](https://github.com/FasterXML/jackson) for JSON serialization/deserialization. It is compatible with version 2.13.4 or higher, but depends on version 2.18.2 by default.\n\nThe SDK throws an exception if it detects an incompatible Jackson version at runtime (e.g. if the default version was overridden in your Maven or Gradle config).\n\nIf the SDK threw an exception, but you're _certain_ the version is compatible, then disable the version check using the `checkJacksonVersionCompatibility` on [`LangsmithOkHttpClient`](langsmith-java-client-okhttp/src/main/kotlin/com/langchain/smith/client/okhttp/LangsmithOkHttpClient.kt) or [`LangsmithOkHttpClientAsync`](langsmith-java-client-okhttp/src/main/kotlin/com/langchain/smith/client/okhttp/LangsmithOkHttpClientAsync.kt).\n\n\u003e [!CAUTION]\n\u003e We make no guarantee that the SDK works correctly when the Jackson version check is disabled.\n\nAlso note that there are bugs in older Jackson versions that can affect the SDK. We don't work around all Jackson bugs ([example](https://github.com/FasterXML/jackson-databind/issues/3240)) and expect users to upgrade Jackson for those instead.\n\n## Network options\n\n### Retries\n\nThe SDK automatically retries 2 times by default, with a short exponential backoff between requests.\n\nOnly the following error types are retried:\n\n- Connection errors (for example, due to a network connectivity problem)\n- 408 Request Timeout\n- 409 Conflict\n- 429 Rate Limit\n- 5xx Internal\n\nThe API may also explicitly instruct the SDK to retry or not retry a request.\n\nTo set a custom number of retries, configure the client using the `maxRetries` method:\n\n```java\nimport com.langchain.smith.client.LangsmithClient;\nimport com.langchain.smith.client.okhttp.LangsmithOkHttpClient;\n\nLangsmithClient client = LangsmithOkHttpClient.builder()\n    .fromEnv()\n    .maxRetries(4)\n    .build();\n```\n\n### Timeouts\n\nRequests time out after 90 seconds by default.\n\nTo set a custom timeout, configure the method call using the `timeout` method:\n\n```java\nimport com.langchain.smith.models.sessions.CustomChartsSection;\n\nCustomChartsSection customChartsSection = client.sessions().dashboard(\n  params, RequestOptions.builder().timeout(Duration.ofSeconds(30)).build()\n);\n```\n\nOr configure the default for all method calls at the client level:\n\n```java\nimport com.langchain.smith.client.LangsmithClient;\nimport com.langchain.smith.client.okhttp.LangsmithOkHttpClient;\nimport java.time.Duration;\n\nLangsmithClient client = LangsmithOkHttpClient.builder()\n    .fromEnv()\n    .timeout(Duration.ofSeconds(30))\n    .build();\n```\n\n### Proxies\n\nTo route requests through a proxy, configure the client using the `proxy` method:\n\n```java\nimport com.langchain.smith.client.LangsmithClient;\nimport com.langchain.smith.client.okhttp.LangsmithOkHttpClient;\nimport java.net.InetSocketAddress;\nimport java.net.Proxy;\n\nLangsmithClient client = LangsmithOkHttpClient.builder()\n    .fromEnv()\n    .proxy(new Proxy(\n      Proxy.Type.HTTP, new InetSocketAddress(\n        \"https://example.com\", 8080\n      )\n    ))\n    .build();\n```\n\n### Connection pooling\n\nTo customize the underlying OkHttp connection pool, configure the client using the `maxIdleConnections` and `keepAliveDuration` methods:\n\n```java\nimport com.langchain.smith.client.LangsmithClient;\nimport com.langchain.smith.client.okhttp.LangsmithOkHttpClient;\nimport java.time.Duration;\n\nLangsmithClient client = LangsmithOkHttpClient.builder()\n    .fromEnv()\n    // If `maxIdleConnections` is set, then `keepAliveDuration` must be set, and vice versa.\n    .maxIdleConnections(10)\n    .keepAliveDuration(Duration.ofMinutes(2))\n    .build();\n```\n\nIf both options are unset, OkHttp's default connection pool settings are used.\n\n### HTTPS\n\n\u003e [!NOTE]\n\u003e Most applications should not call these methods, and instead use the system defaults. The defaults include\n\u003e special optimizations that can be lost if the implementations are modified.\n\nTo configure how HTTPS connections are secured, configure the client using the `sslSocketFactory`, `trustManager`, and `hostnameVerifier` methods:\n\n```java\nimport com.langchain.smith.client.LangsmithClient;\nimport com.langchain.smith.client.okhttp.LangsmithOkHttpClient;\n\nLangsmithClient client = LangsmithOkHttpClient.builder()\n    .fromEnv()\n    // If `sslSocketFactory` is set, then `trustManager` must be set, and vice versa.\n    .sslSocketFactory(yourSSLSocketFactory)\n    .trustManager(yourTrustManager)\n    .hostnameVerifier(yourHostnameVerifier)\n    .build();\n```\n\n### Custom HTTP client\n\nThe SDK consists of three artifacts:\n\n- `langsmith-java-core`\n  - Contains core SDK logic\n  - Does not depend on [OkHttp](https://square.github.io/okhttp)\n  - Exposes [`LangsmithClient`](langsmith-java-core/src/main/kotlin/com/langchain/smith/client/LangsmithClient.kt), [`LangsmithClientAsync`](langsmith-java-core/src/main/kotlin/com/langchain/smith/client/LangsmithClientAsync.kt), [`LangsmithClientImpl`](langsmith-java-core/src/main/kotlin/com/langchain/smith/client/LangsmithClientImpl.kt), and [`LangsmithClientAsyncImpl`](langsmith-java-core/src/main/kotlin/com/langchain/smith/client/LangsmithClientAsyncImpl.kt), all of which can work with any HTTP client\n- `langsmith-java-client-okhttp`\n  - Depends on [OkHttp](https://square.github.io/okhttp)\n  - Exposes [`LangsmithOkHttpClient`](langsmith-java-client-okhttp/src/main/kotlin/com/langchain/smith/client/okhttp/LangsmithOkHttpClient.kt) and [`LangsmithOkHttpClientAsync`](langsmith-java-client-okhttp/src/main/kotlin/com/langchain/smith/client/okhttp/LangsmithOkHttpClientAsync.kt), which provide a way to construct [`LangsmithClientImpl`](langsmith-java-core/src/main/kotlin/com/langchain/smith/client/LangsmithClientImpl.kt) and [`LangsmithClientAsyncImpl`](langsmith-java-core/src/main/kotlin/com/langchain/smith/client/LangsmithClientAsyncImpl.kt), respectively, using OkHttp\n- `langsmith-java`\n  - Depends on and exposes the APIs of both `langsmith-java-core` and `langsmith-java-client-okhttp`\n  - Does not have its own logic\n\nThis structure allows replacing the SDK's default HTTP client without pulling in unnecessary dependencies.\n\n#### Customized [`OkHttpClient`](https://square.github.io/okhttp/3.x/okhttp/okhttp3/OkHttpClient.html)\n\n\u003e [!TIP]\n\u003e Try the available [network options](#network-options) before replacing the default client.\n\nTo use a customized `OkHttpClient`:\n\n1. Replace your [`langsmith-java` dependency](#installation) with `langsmith-java-core`\n2. Copy `langsmith-java-client-okhttp`'s [`OkHttpClient`](langsmith-java-client-okhttp/src/main/kotlin/com/langchain/smith/client/okhttp/OkHttpClient.kt) class into your code and customize it\n3. Construct [`LangsmithClientImpl`](langsmith-java-core/src/main/kotlin/com/langchain/smith/client/LangsmithClientImpl.kt) or [`LangsmithClientAsyncImpl`](langsmith-java-core/src/main/kotlin/com/langchain/smith/client/LangsmithClientAsyncImpl.kt), similarly to [`LangsmithOkHttpClient`](langsmith-java-client-okhttp/src/main/kotlin/com/langchain/smith/client/okhttp/LangsmithOkHttpClient.kt) or [`LangsmithOkHttpClientAsync`](langsmith-java-client-okhttp/src/main/kotlin/com/langchain/smith/client/okhttp/LangsmithOkHttpClientAsync.kt), using your customized client\n\n### Completely custom HTTP client\n\nTo use a completely custom HTTP client:\n\n1. Replace your [`langsmith-java` dependency](#installation) with `langsmith-java-core`\n2. Write a class that implements the [`HttpClient`](langsmith-java-core/src/main/kotlin/com/langchain/smith/core/http/HttpClient.kt) interface\n3. Construct [`LangsmithClientImpl`](langsmith-java-core/src/main/kotlin/com/langchain/smith/client/LangsmithClientImpl.kt) or [`LangsmithClientAsyncImpl`](langsmith-java-core/src/main/kotlin/com/langchain/smith/client/LangsmithClientAsyncImpl.kt), similarly to [`LangsmithOkHttpClient`](langsmith-java-client-okhttp/src/main/kotlin/com/langchain/smith/client/okhttp/LangsmithOkHttpClient.kt) or [`LangsmithOkHttpClientAsync`](langsmith-java-client-okhttp/src/main/kotlin/com/langchain/smith/client/okhttp/LangsmithOkHttpClientAsync.kt), using your new client class\n\n## Undocumented API functionality\n\nThe SDK is typed for convenient usage of the documented API. However, it also supports working with undocumented or not yet supported parts of the API.\n\n### Parameters\n\nTo set undocumented parameters, call the `putAdditionalHeader`, `putAdditionalQueryParam`, or `putAdditionalBodyProperty` methods on any `Params` class:\n\n```java\nimport com.langchain.smith.core.JsonValue;\nimport com.langchain.smith.models.sessions.SessionDashboardParams;\n\nSessionDashboardParams params = SessionDashboardParams.builder()\n    .putAdditionalHeader(\"Secret-Header\", \"42\")\n    .putAdditionalQueryParam(\"secret_query_param\", \"42\")\n    .putAdditionalBodyProperty(\"secretProperty\", JsonValue.from(\"42\"))\n    .build();\n```\n\nThese can be accessed on the built object later using the `_additionalHeaders()`, `_additionalQueryParams()`, and `_additionalBodyProperties()` methods.\n\nTo set a documented parameter or property to an undocumented or not yet supported _value_, pass a [`JsonValue`](langsmith-java-core/src/main/kotlin/com/langchain/smith/core/Values.kt) object to its setter:\n\n```java\nimport com.langchain.smith.models.sessions.CustomChartsSectionRequest;\nimport com.langchain.smith.models.sessions.SessionDashboardParams;\n\nSessionDashboardParams params = SessionDashboardParams.builder()\n    .customChartsSectionRequest(CustomChartsSectionRequest.builder().build())\n    .build();\n```\n\nThe most straightforward way to create a [`JsonValue`](langsmith-java-core/src/main/kotlin/com/langchain/smith/core/Values.kt) is using its `from(...)` method:\n\n```java\nimport com.langchain.smith.core.JsonValue;\nimport java.util.List;\nimport java.util.Map;\n\n// Create primitive JSON values\nJsonValue nullValue = JsonValue.from(null);\nJsonValue booleanValue = JsonValue.from(true);\nJsonValue numberValue = JsonValue.from(42);\nJsonValue stringValue = JsonValue.from(\"Hello World!\");\n\n// Create a JSON array value equivalent to `[\"Hello\", \"World\"]`\nJsonValue arrayValue = JsonValue.from(List.of(\n  \"Hello\", \"World\"\n));\n\n// Create a JSON object value equivalent to `{ \"a\": 1, \"b\": 2 }`\nJsonValue objectValue = JsonValue.from(Map.of(\n  \"a\", 1,\n  \"b\", 2\n));\n\n// Create an arbitrarily nested JSON equivalent to:\n// {\n//   \"a\": [1, 2],\n//   \"b\": [3, 4]\n// }\nJsonValue complexValue = JsonValue.from(Map.of(\n  \"a\", List.of(\n    1, 2\n  ),\n  \"b\", List.of(\n    3, 4\n  )\n));\n```\n\nNormally a `Builder` class's `build` method will throw [`IllegalStateException`](https://docs.oracle.com/javase/8/docs/api/java/lang/IllegalStateException.html) if any required parameter or property is unset.\n\nTo forcibly omit a required parameter or property, pass [`JsonMissing`](langsmith-java-core/src/main/kotlin/com/langchain/smith/core/Values.kt):\n\n```java\nimport com.langchain.smith.core.JsonMissing;\nimport com.langchain.smith.models.sessions.CustomChartsSectionRequest;\nimport com.langchain.smith.models.sessions.SessionDashboardParams;\n\nSessionDashboardParams params = SessionDashboardParams.builder()\n    .customChartsSectionRequest(CustomChartsSectionRequest.builder().build())\n    .sessionId(JsonMissing.of())\n    .build();\n```\n\n### Response properties\n\nTo access undocumented response properties, call the `_additionalProperties()` method:\n\n```java\nimport com.langchain.smith.core.JsonValue;\nimport java.util.Map;\n\nMap\u003cString, JsonValue\u003e additionalProperties = client.sessions().dashboard(params)._additionalProperties();\nJsonValue secretPropertyValue = additionalProperties.get(\"secretProperty\");\n\nString result = secretPropertyValue.accept(new JsonValue.Visitor\u003c\u003e() {\n    @Override\n    public String visitNull() {\n        return \"It's null!\";\n    }\n\n    @Override\n    public String visitBoolean(boolean value) {\n        return \"It's a boolean!\";\n    }\n\n    @Override\n    public String visitNumber(Number value) {\n        return \"It's a number!\";\n    }\n\n    // Other methods include `visitMissing`, `visitString`, `visitArray`, and `visitObject`\n    // The default implementation of each unimplemented method delegates to `visitDefault`, which throws by default, but can also be overridden\n});\n```\n\nTo access a property's raw JSON value, which may be undocumented, call its `_` prefixed method:\n\n```java\nimport com.langchain.smith.core.JsonField;\nimport java.util.Optional;\n\nJsonField\u003cObject\u003e field = client.sessions().dashboard(params)._field();\n\nif (field.isMissing()) {\n  // The property is absent from the JSON response\n} else if (field.isNull()) {\n  // The property was set to literal null\n} else {\n  // Check if value was provided as a string\n  // Other methods include `asNumber()`, `asBoolean()`, etc.\n  Optional\u003cString\u003e jsonString = field.asString();\n\n  // Try to deserialize into a custom type\n  MyClass myObject = field.asUnknown().orElseThrow().convert(MyClass.class);\n}\n```\n\n### Response validation\n\nIn rare cases, the API may return a response that doesn't match the expected type. For example, the SDK may expect a property to contain a `String`, but the API could return something else.\n\nBy default, the SDK will not throw an exception in this case. It will throw [`LangChainInvalidDataException`](langsmith-java-core/src/main/kotlin/com/langchain/smith/errors/LangChainInvalidDataException.kt) only if you directly access the property.\n\nIf you would prefer to check that the response is completely well-typed upfront, then either call `validate()`:\n\n```java\nimport com.langchain.smith.models.sessions.CustomChartsSection;\n\nCustomChartsSection customChartsSection = client.sessions().dashboard(params).validate();\n```\n\nOr configure the method call to validate the response using the `responseValidation` method:\n\n```java\nimport com.langchain.smith.models.sessions.CustomChartsSection;\n\nCustomChartsSection customChartsSection = client.sessions().dashboard(\n  params, RequestOptions.builder().responseValidation(true).build()\n);\n```\n\nOr configure the default for all method calls at the client level:\n\n```java\nimport com.langchain.smith.client.LangsmithClient;\nimport com.langchain.smith.client.okhttp.LangsmithOkHttpClient;\n\nLangsmithClient client = LangsmithOkHttpClient.builder()\n    .fromEnv()\n    .responseValidation(true)\n    .build();\n```\n\n## FAQ\n\n### Why don't you use plain `enum` classes?\n\nJava `enum` classes are not trivially [forwards compatible](https://www.stainless.com/blog/making-java-enums-forwards-compatible). Using them in the SDK could cause runtime exceptions if the API is updated to respond with a new enum value.\n\n### Why do you represent fields using `JsonField\u003cT\u003e` instead of just plain `T`?\n\nUsing `JsonField\u003cT\u003e` enables a few features:\n\n- Allowing usage of [undocumented API functionality](#undocumented-api-functionality)\n- Lazily [validating the API response against the expected shape](#response-validation)\n- Representing absent vs explicitly null values\n\n### Why don't you use [`data` classes](https://kotlinlang.org/docs/data-classes.html)?\n\nIt is not [backwards compatible to add new fields to a data class](https://kotlinlang.org/docs/api-guidelines-backward-compatibility.html#avoid-using-data-classes-in-your-api) and we don't want to introduce a breaking change every time we add a field to a class.\n\n### Why don't you use checked exceptions?\n\nChecked exceptions are widely considered a mistake in the Java programming language. In fact, they were omitted from Kotlin for this reason.\n\nChecked exceptions:\n\n- Are verbose to handle\n- Encourage error handling at the wrong level of abstraction, where nothing can be done about the error\n- Are tedious to propagate due to the [function coloring problem](https://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-function)\n- Don't play well with lambdas (also due to the function coloring problem)\n\n## Semantic versioning\n\nThis package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:\n\n1. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals.)_\n2. Changes that we do not expect to impact the vast majority of users in practice.\n\nWe take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.\n\nWe are keen for your feedback; please open an [issue](https://www.github.com/langchain-ai/langsmith-java/issues) with questions, bugs, or suggestions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flangchain-ai%2Flangsmith-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flangchain-ai%2Flangsmith-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flangchain-ai%2Flangsmith-java/lists"}