Authentication

You'll need to authenticate your requests to access any of the endpoints in the Composable Prompts API. In this guide, we'll look at how authentication works. We use two type of api keys: private and public.

The private key starts with "sk*" and the public key starts with "pk*". The private key is used to access the whole API, while the public key can only be used to execute interactions.

Using an API key

The way to authenticate with the Composable Prompts API is by using an API Key and a Project Id. To authenticate with curl, pass the API Key in the Authorization header:

Example request with bearer token

curl https://api.composableprompts.com/v1/account/info \
  -H "Authorization: Bearer {api_key}" \

Always keep your key safe and reset it if you suspect it has been compromised.

Using the JavaScript/TypeScript SDK

If you use our official SDK, simply pass the API Key and Project Id when instantiating the client:

import { StudioClient } from '@composableai/sdk'
const client = new StudioClient({
  apikey: '{api_key}',
})

// Now you can use the client to make requests
const info = await client.account.info()
const interactions = await client.interactions.list()

Using generated interaction classes

As we've explained in the quickstart guide you can access interactions through a strong typed typescript class which can be generating using the Composable Prompts CLI.

In that case you can pass the API Key as an option when instantiating the class. There is no need to pass the project id since the generated class already knows it.

import { MyInteractionClass } from "./MyInteractionClass/index.js"

const interaction = new MyInteractionClass({
    apikey: "YOUR_API_KEY_HERE"
});

const run = await interaction.execute();

Was this page helpful?