Skip to Content

Generate an SDK

Generate your Ontology SDK in Developer Console or locally with osdk unstable typescript generate or @osdk/foundry-sdk-generator, and update it when the Ontology changes.

Foundry docsDeveloper Console

Your generated SDK holds typed definitions for the object types, links, actions, functions, and interfaces your app uses. Generate it in Developer Console and install it from your Foundry npm registry, or generate it yourself from the command line.

Choose a method

MethodOutputUse it when
Developer ConsoleA versioned npm package in your Foundry registry.Almost always. Apps from @osdk/create-app expect it.
osdk unstable typescript generateTypeScript source files in a folder of your project.You want the SDK in your repository, or you work offline from a saved Ontology file.
@osdk/foundry-sdk-generatorA built npm package directory you can pack or publish.You publish SDK packages from your own pipeline.

Generate in Developer Console

Choose the resources

In your application in Developer Console, add the object types, link types, actions, functions, and interfaces your app uses to the application's SDK. Only those resources are generated.

Generate a version

On SDK versions, generate a new version with the npm package type and the latest generator. The install instructions show the package name, such as @my-app/sdk, and your registry URL.

Install it

Point your SDK's npm scope at the Foundry registry in .npmrc, then install:

npm install @my-app/sdk@latest

Installation covers the .npmrc lines, the token, and the other packages you need.

What the package exports

ExportDescription
Object types, such as EmployeePass to client(Employee) to query.
Actions, such as modifyEmployeePass to client(modifyEmployee).applyAction(...).
Functions and interfacesPass to client(...) the same way.
$ontologyRidThe Ontology RID, for createClient.
$branchThe Foundry branch RID the SDK was generated on, or undefined for main. See Develop on Foundry branches.

Update the SDK when the Ontology changes

The SDK is a snapshot of the Ontology when you generated it. When you add a resource to the SDK, or a property, parameter, or link you use changes:

  1. Generate a new version in Developer Console.

  2. Install it:

    npm install @my-app/sdk@latest
  3. Run your type checker. Renamed or removed properties and parameters show up as type errors where your code uses them.

The SDK has a peer dependency on the @osdk/client version that generated it. If npm reports a peer conflict, align @osdk/client, @osdk/api, and @osdk/react as described in Version compatibility. On a Foundry branch, osdk branch sync picks the branch's SDK version instead of latest.

Generate locally

osdk unstable typescript generate from @osdk/cli writes the SDK as TypeScript source files into your project. It is unstable: flags and output can change in any release.

npx @osdk/cli@latest unstable typescript generate \
  --foundryUrl https://example.palantirfoundry.com \
  --clientId <your-client-id> \
  --outDir src/generatedNoCheck \
  --version dev \
  --packageType module \
  --ontologyWritePath ontology.json

The CLI opens your browser to sign in, with http://localhost:8080/auth/callback as the redirect URL, so allow that URL on OAuth & scopes and keep port 8080 free. It generates every object type, action, function, and interface the client can see in the Ontology, except functions that return Ontology edits. If the client can see more than one Ontology, pass --ontologyRid. Pass --branch <branch RID> to read a branch's Ontology.

--ontologyWritePath saves the loaded metadata so you can regenerate later without signing in.

Import from the generated folder instead of a package:

src/client.ts
import { createClient } from "@osdk/client";
import { createPublicOauthClient } from "@osdk/oauth";
import { $ontologyRid } from "./generatedNoCheck/index.js";

const foundryUrl = "https://example.palantirfoundry.com";

const auth = createPublicOauthClient(
  "<your-client-id>",
  foundryUrl,
  "http://localhost:8080/auth/callback",
);

export const client = createClient(foundryUrl, $ontologyRid, auth);

Unless you pass --skipPackageJsonUpdate, the command also edits the nearest package.json above --outDir: it adds @osdk/api and @osdk/client as peer dependencies and @osdk/api as a dev dependency, and sets any existing @osdk/api and @osdk/client entries to the versions the CLI was built with. Install @osdk/client as a regular dependency of your app yourself.

All flags are in the CLI reference.

Build a package with @osdk/foundry-sdk-generator

@osdk/foundry-sdk-generator loads the resources you name from Foundry and writes a compiled npm package with ESM, CommonJS, and bundled type definitions.

npx @osdk/foundry-sdk-generator generatePackage \
  --authToken "$FOUNDRY_TOKEN" \
  --foundryHostname example.palantirfoundry.com \
  --ontology ri.ontology.main.ontology.<id> \
  --objectTypes Employee Office \
  --linkTypes Employee.lead Employee.reports Employee.office Office.occupants \
  --actionTypes modifyEmployee \
  --interfaceTypes Worker \
  --packageName @my-app/sdk \
  --packageVersion 0.1.0 \
  --outputDir ./out

The package is written to <outputDir>/<packageName>, here ./out/@my-app/sdk, with a peerDependencies entry for @osdk/client. Pack or publish it from there with npm.

OptionTypeDescription
--authTokenstringA Foundry token. Required.
--foundryHostnamestringYour stack, such as example.palantirfoundry.com. A full https:// URL also works. Required.
--ontologystringThe Ontology RID or API name.
--packageNamestringThe npm package name. Required.
--packageVersionstringThe package version. Must be SemVer. Required.
--outputDirstringThe directory to write the package under. Required.
--objectTypesstring[]Object type API names.
--linkTypesstring[]Links to include, as ObjectTypeApiName.linkApiName.
--actionTypesstring[]Action type API names.
--queryTypesstring[]Function API names. Add :<version> to pin a version, such as countEmployees:1.2.0.
--interfaceTypesstring[]Interface API names.
--agentsstring[]AIP Agents, as apiName:version.
--experimentalOntologyMetadatabooleanAlso export the raw metadata at ./experimental/ontology-metadata. Experimental.

Each list flag takes space-separated values. The generator includes only what you list: an object type's links are left out unless you pass them in --linkTypes, and generation fails if a requested resource is missing.

On this page