What You’ll Build
A backend service that can invoke Profy Experts, with SSE streaming responses connected to a frontend chat interface. When complete, your application will have:- Invoke any published Expert using the
ProfySDK - Multi-turn conversation context retention (
sessionId) - SSE stream parsing with structured event handling
- Comprehensive error handling and retry strategies
What Is an Expert
An Expert is an AI Agent product on the Profy platform, published by creators on the Marketplace. Each Expert consists of:
Through the SDK’s
agents.run() / agents.runStream() methods, your application can invoke these Experts just like calling a function.
Prerequisites
Before getting started, make sure you have:- Profy API Key: A
sk-pro-prefixed API Key created in the Platform Console - Target Expert Identifier: The unique identifier of the Expert you want to invoke
Step 1: Find the Expert Identifier
Every published Expert has a uniqueidentifier (slug format) used for API calls.
How to find it:
- Marketplace page — Open the Expert’s detail page; the last path segment in the URL is the identifier, e.g.,
https://app.profy.cn/expert/data-analyst→data-analyst - Studio — If you’re the Expert’s creator, the identifier is shown in the basic information section of the editing page
Step 2: Single-Turn Invocation
Use the SDK’sagents.run() method to get the complete response at once.
agents.run() internally consumes the entire SSE stream and returns the aggregated result:
Step 3: Multi-Turn Conversations
By passing asessionId parameter, the Expert continues the conversation within the same session context, retaining previous message history and memory.
The
sessionId is generated and managed by your application. All calls under the same sessionId share conversation context. A new sessionId starts a fresh conversation.Step 4: Streaming Output
Useagents.runStream() for real-time SSE event streaming, ideal for building typewriter-style chat interfaces.
SSE Event Types
Step 5: Error Handling
The SDK throws specific exceptions based on HTTP status codes:Step 6: Building a Chat Interface
Connect streaming output to a frontend chat interface. The frontend calls through your backend proxy, which holds the API Key:The frontend doesn’t call the Profy API directly — requests go through your backend proxy (
/api/expert/invoke), which holds the API Key and forwards the SSE stream. This avoids exposing the API Key on the client side.Complete Backend Example
Wrap Expert invocation as an API endpoint that the frontend can consume directly:Expert Invocation vs AI Model Calls
The Profy SDK provides two types of AI calls. Choose the right one for your scenario:Next Steps
SDK Quick Start
Install the SDK, create an API Key, and make your first call
AI Token-Metered Billing
Build token-metered AI apps with chat.completions
Per-Use Billing
Implement per-call billing with ProfyApp reportEvent
Token Management
OAuth Token persistence and concurrent refresh best practices

