Skip to main content

Install an SDK

The Shaped SDK simplifies interactions with Shaped's V2 Query API, making it easier to integrate our services into your applications.

This guide will walk you through the installation process for different programming languages.

Install the SDK

Install
npm install @shaped.ai/client

Verify Installation

Use the following commands to verify the packages have installed correctly.

npm list @shaped.ai/client

Making Queries

The V2 Query API uses ShapedQL (SQL) to retrieve and rank items. Here's how to make queries using the REST API:

// Get personalized recommendations for a user.
const response = await fetch("https://api.shaped.ai/v2/engines/your_engine_name/query", {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": "your_api_key"
},
body: JSON.stringify({
query: "SELECT * FROM similarity(embedding_ref='als', limit=100, encoder='interaction_pooling', input_user_id=$user_id) LIMIT 20",
parameters: {
user_id: "user123"
},
return_metadata: true
})
})
const recommendations = await response.json()
// Get items with filtering.
const response = await fetch("https://api.shaped.ai/v2/engines/your_engine_name/query", {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": "your_api_key"
},
body: JSON.stringify({
query: "SELECT * FROM similarity(embedding_ref='als', limit=100, encoder='interaction_pooling', input_user_id=$user_id) WHERE category = 'sports' AND price < 100 LIMIT 20",
parameters: {
user_id: "user123"
},
return_metadata: true
})
})
// Execute a saved query.
const response = await fetch("https://api.shaped.ai/v2/engines/your_engine_name/queries/get_recommended_items", {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": "your_api_key"
},
body: JSON.stringify({
parameters: {
user_id: "user123"
}
})
})
const recommendations = await response.json()

For more query examples and ShapedQL syntax, see the Query Reference.