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.
Prerequisites
Section titled “Prerequisites”Before you start using the PromptTK SDK, ensure you have the following:
- A valid API key from PromptTK.
- You can obtain this by signing up on the PromptTK website.
- Your unique user ID.
- This can be found in your account settings.
- Node.js v20.x or later installed on your machine.
- You can download it from Node.js official website.
Installation
Section titled “Installation”To install the PromptTK SDK, you can use npm:
npm install @devvle/ptk-api-sdkSDK Setup
Section titled “SDK Setup”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.
Making API Calls directly
Section titled “Making API Calls directly”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/Headers
Section titled “Headers”| Header | Value |
|---|---|
Content-Type | application/json |
Authorization | Bearer your-api-key |
x-user-id | your-user-id |
Example Request
Section titled “Example Request”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}`);}