Foundry APIs expose a variety of functionality that you can leverage with the Foundry platform SDK library through functions. You can use the platform SDK to build functions for administrative or governance workflows, interact with schedules and builds, access media sets, and more.
First-class authentication is not supported for TypeScript v1 functions. We recommend using Python functions and TypeScript v2 functions for these workflows.
To install the Foundry platform SDK, navigate to the Libraries side panel in your code repository and search for the SDK name: foundry-platform-sdk
for Python, or @osdk/foundry
for TypeScript.
Your function requires authentication to interact with Foundry APIs. This process involves instantiating an authenticated “client” through which you can make requests to the Foundry APIs through the SDK. To help with this, install the appropriate library:foundry-sdk-runtime
in Python, or @osdk/client
in TypeScript. The @osdk/client
library should come pre-installed in any TypeScript v2 repository.
Once your function is authenticated, you can start using Foundry APIs. The examples below show how to call a language model or query media sets in both Python and TypeScript:
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
import { Client } from "@osdk/client"; import { Functions } from "@osdk/foundry"; export default async function useLlm( client: Client, // This parameter gets populated at runtime with a client that has permissions equal to the user calling the function prompt: string ): Promise<string> { const promptMessage = [ { role: "USER", content: prompt } ]; const result = await Functions.Queries.execute( client, "com.foundry.languagemodelservice.models.gpt41.CreateChatCompletion", { parameters: { messages: promptMessage } }, { preview: true, // TODO: Remove; only needed for testing in Live Preview } ); return result.value["completion"] as string; }