> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://docs.chrt.com/staging/sd-ks/sdk/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.chrt.com/_mcp/server. # Chrt SDKs ## Available SDKs | Language | Package | Install | | ---------- | -------------------------- | ----------------------------------- | | TypeScript | `@chrt-inc/typescript-sdk` | `npm i -s @chrt-inc/typescript-sdk` | | Java | `com.chrt:java-sdk` | Via Maven Central | | Swift | `Chrt` | Via Swift Package Manager | ## TypeScript SDK ### Installation ```bash npm i -s @chrt-inc/typescript-sdk ``` ### Usage Instantiate and use the client with the following: ```typescript import { ChrtClient } from "@chrt-inc/typescript-sdk"; const client = new ChrtClient({ token: "YOUR_TOKEN" }); await client.root.postAuthd(); ``` ### Request And Response Types The SDK exports all request and response types as TypeScript interfaces. Simply import them with the following namespace: ```typescript import { Chrt } from "@chrt-inc/typescript-sdk"; const request: Chrt.TemplateReq = { ... }; ``` ### Exception Handling When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error will be thrown. ```typescript import { ChrtError } from "@chrt-inc/typescript-sdk"; try { await client.root.postAuthd(...); } catch (err) { if (err instanceof ChrtError) { console.log(err.statusCode); console.log(err.message); console.log(err.body); } } ``` ### Advanced #### Additional Headers If you would like to send additional headers as part of the request, use the headers request option. ```typescript const response = await client.root.postAuthd(..., { headers: { 'X-Custom-Header': 'custom value' } }); ``` #### Retries The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long as the request is deemed retriable and the number of retry attempts has not grown larger than the configured retry limit (default: 2). A request is deemed retriable when any of the following HTTP status codes is returned: * 408 (Timeout) * 429 (Too Many Requests) * 5XX (Internal Server Errors) Use the maxRetries request option to configure this behavior. ```typescript const response = await client.root.postAuthd(..., { maxRetries: 0 // override maxRetries at the request level }); ``` #### Timeouts The SDK defaults to a 60 second timeout. Use the timeoutInSeconds option to configure this behavior. ```typescript const response = await client.root.postAuthd(..., { timeoutInSeconds: 30 // override timeout to 30s }); ``` #### Aborting Requests The SDK allows users to abort requests at any point by passing in an abort signal. ```typescript const controller = new AbortController(); const response = await client.root.postAuthd(..., { abortSignal: controller.signal }); controller.abort(); // aborts the request ``` #### Runtime Compatibility The SDK defaults to node-fetch but will use the global fetch client if present. The SDK works in the following runtimes: * Node.js 18+ * Vercel * Cloudflare Workers * Deno v1.25+ * Bun 1.0+ * React Native #### Customizing Fetch Client The SDK provides a way for you to customize the underlying HTTP client / Fetch function. If you're running in an unsupported environment, this provides a way for you to break glass and ensure the SDK works. ```typescript import { ChrtClient } from "@chrt-inc/typescript-sdk"; const client = new ChrtClient({ ... fetcher: // provide your implementation here }); ``` ### Example Here's a practical example of integrating the Chrt SDK in a Next.js application with authentication: #### Setting up the Client with Authentication Create a utility function to handle client instantiation with dynamic authentication: ```typescript // app/providers/ChrtClient/getChrtClient.ts import "server-only"; import { ChrtClient } from "@chrt-inc/typescript-sdk"; import { auth } from "@clerk/nextjs/server"; export async function getChrtClient(): Promise { const { getToken } = await auth(); const token = await getToken(); return new ChrtClient({ environment: process.env.NEXT_PUBLIC_CHRT_API_BASE_URL || "https://api.dev.chrt.com", token: () => token!, }); } ``` #### Using the Client in Server Components ```typescript // app/(app)/orders/page.tsx import { getChrtClient } from "../../app/providers/ChrtClient"; export default async function OrdersPage() { const chrt = await getChrtClient(); try { const orders = await chrt.shipping.orders.expanded.listForCourierOperatorsV1(); console.log("Orders:", orders); return (
{/* Render your orders */}
); } catch (error) { console.error("Failed to fetch orders:", error); return
Error loading orders
; } } ``` #### Client Provider Setup For client-side usage, you can also set up a React context provider: ```typescript // app/providers/ChrtClient/index.ts export { getChrtClient } from "./getChrtClient"; // Server-side utility export { ChrtClientProvider, useChrtClient } from "./ChrtClientProvider"; // Client-side provider ``` This pattern allows you to seamlessly use the Chrt SDK across your application with proper authentication handling. ## Java SDK ### Installation Add the dependency to your `pom.xml`: ```xml com.chrt java-sdk 1.689.0 ``` Or with Gradle: ```groovy implementation 'com.chrt:java-sdk:1.689.0' ``` Pin Java to the same PR-based version as the other SDKs (`1.{PR_NUMBER}.{PATCH}`), then update deliberately when you are ready for new generated API changes. The Java SDK is generated alongside the TypeScript and Swift SDKs and provides the same API coverage. See the [API Reference](/api-reference) for full endpoint documentation with Java snippets. ## Swift SDK The Swift SDK is available via Swift Package Manager. Add the following to your `Package.swift`: ```swift .package(url: "https://github.com/chrt-inc/swift-sdk", .upToNextMinor(from: "1.689.0")) ``` Pin Swift to the same PR-based version as the other SDKs (`1.{PR_NUMBER}.{PATCH}`). Prefer `upToNextMinor` if you want patch updates for the same server PR, or an exact version if you want fully locked generated API shapes. The Swift SDK is ideal for building native iOS applications that integrate with CHRT -- for example, driver apps that send location updates and complete task artifacts. ## Contributing While we value open-source contributions to these SDKs, the libraries are generated programmatically. Additions made directly would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us! On the other hand, contributions to the READMEs are always very welcome! --- For more information about our APIs and integrations, check out our [API Reference](/api-reference) or contact our [Support team](/support). > Official SDKs for integrating with the Chrt API from TypeScript, Java, and Swift.