Skip to content

Getting Started

Please ensure you have visited the PromptTK website to create an account and obtain your API key. The SDK is designed to work seamlessly with the PromptTK API, enabling you to leverage its capabilities in your applications.

Before you start using the PromptTK SDK, ensure you have the following:

To install the PromptTK SDK, you can use npm:

Terminal window
npm install @devvle/ptk-api-sdk

Here’s a simple example of how to get set up with the PromptTK SDK:

import { PromptTK } from "@devvle/ptk-api-sdk";
const promptTK = new PromptTK({
userId: "your-user-id",
apiKey: "your-api-key",
});

This code initializes the PromptTK SDK with your user ID and API key. Make sure to replace "your-user-id" and "your-api-key" with your actual credentials. It is recommended to store your API key securely and not hard-code it directly into your source code. Consider using environment variables or a secure vault service for production applications.

We also recommend creating your sdk instance in a Context Provider when using a React based framework, to simplify access to the SDK across your application.

You can also use our api endpoints directly without the SDK. The API is a RESTful service that allows you to interact with PromptTK’s capabilities. Here’s an example of how to make a direct API call using fetch:

https://api.prompttk.com/
HeaderValue
Content-Typeapplication/json
AuthorizationBearer your-api-key
x-user-idyour-user-id
try {
const response = await fetch(`${API_ENDPOINT}/dev/validate/key`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${<your-api-key>}`,
'x-user-id': <your-user-id>,
}
});
if (!response.ok) {
const errorText = await response.text();
throw new Error(`API request failed with status ${response.status}: ${errorText}`);
}
return response;
} catch (error: any) {
throw new Error(`Failed to validate api key: ${error.message}`);
}