Skip to main content
How-to Guide

Use user profiles

Create profile schemas, extract profiles, and retrieve user profiles via API

User profiles extract structured user attributes (e.g., age, occupation, preferences) from conversations. For console configuration, see Configure memory rules. This page covers the full API workflow: create a profile schema, extract from a conversation, and retrieve the profile.

Prerequisites

  • A memory created or using the default
  • DASHSCOPE_API_KEY configured

Full workflow

Create schema → Add conversation and extract → Get user profile.
# 1. Create profile schema (CreateProfileSchema)
curl -X POST https://dashscope.aliyuncs.com/api/v2/apps/memory/profile_schemas \
  --header "Authorization: Bearer $DASHSCOPE_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "name": "User basic profile",
    "description": "User info with age and interests",
    "attributes": [
      {"name": "Age", "description": "User age"},
      {"name": "Hobby", "description": "User hobbies"},
      {"name": "Occupation", "description": "User occupation"}
    ]
  }'

# 2. Add conversation and extract profile (AddMemory with profile_schema_id)
curl -X POST https://dashscope.aliyuncs.com/api/v2/apps/memory/add \
  --header "Authorization: Bearer $DASHSCOPE_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "user_id": "user_001",
    "messages": [
      {"role": "user", "content": "I am 28, a software engineer. I play football on weekends."},
      {"role": "assistant", "content": "Nice to meet you!"}
    ],
    "profile_schema": "YOUR_SCHEMA_ID"
  }'

# 3. Get user profile (GetUserProfile, wait 3s first)
curl -X GET "https://dashscope.aliyuncs.com/api/v2/apps/memory/profile_schemas/{YOUR_SCHEMA_ID}/user_profile?user_id=user_001" \
  --header "Authorization: Bearer $DASHSCOPE_API_KEY" \
  --header "Content-Type: application/json"
Profile extraction is asynchronous — wait about 3 seconds after adding a conversation before retrieving.
After profiles are set up, continue to manage memories to view and search existing memories.