What You’ll Build
An AI writing assistant: users enter a topic, and AI generates a draft article. Each call is billed based on actual token consumption — you just need an API Key, and the Profy SDK handles model calls and usage tracking. The end result:- Use the
ProfySDK’schat.completions.createto call AI models - Support both streaming and non-streaming modes
- SDK automatically handles SSE parsing, error mapping, and timeouts
- Token usage is returned in responses; the platform tracks it automatically
Calling Method Comparison
Prerequisites
- Have a Profy developer account
- Created an API Key (
sk-pro-prefix) in the Platform Console - Installed the SDK:
npm install @profy-ai/sdkorpip install profy-sdk
Step 1: Initialize the Client
Step 2: Non-Streaming Call
ChatResponse:
Step 3: Streaming Call
Setstream: true for real-time streaming output, ideal for typewriter-style chat interfaces.
Step 4: Error Handling
The SDK throws typed exceptions based on HTTP status codes:Step 5: Query Available Models
The available model list depends on the platform administrator’s configuration. Common models include
deepseek-chat, deepseek-reasoner, qwen-plus, etc.Complete Example
An AI writing assistant backend with streaming and error handling.OpenAI SDK Compatibility (Alternative)
Profy’s/v1/chat/completions endpoint is OpenAI-compatible, so you can use the official OpenAI SDK directly:
Next Steps
Per-Use Billing
Implement per-call billing with ProfyApp reportEvent
Expert Invocation
Invoke published AI Experts on the platform
Next.js Full-Stack Integration
Complete OAuth + billing + AI call full-stack application
SDK Quick Start
Install SDK, create API Key, first call

