Base URL: https://safyan.ai — Authentication: Bearer sfk_...
Drop-in replacement. Change baseURL to https://safyan.ai/v1. Every prompt is optimized before reaching the AI.
| Field | Type | Required | Description |
|---|---|---|---|
| model | string | required | safyan-auto (best model picked), safyan-fast (compile-only, half cost), or any model ID |
| messages | array | required | Array of {role, content} objects. Max 200 messages, 100K chars per message. |
| stream | boolean | optional | Enable SSE streaming. Default: false |
| max_tokens | integer | optional | Max response tokens. Default: 4096 |
{
"id": "sfyn-chatcmpl-abc123...",
"object": "chat.completion",
"created": 1711756800,
"model": "claude-haiku-4-5-20251001",
"choices": [{
"index": 0,
"message": { "role": "assistant", "content": "..." },
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 142,
"completion_tokens": 89,
"total_tokens": 231
},
"safyan": {
"safyan_primitives": ["PRIME", "LOCK", "BOUND", "SHAPE", "NEGATE"],
"safyan_mode": "standard",
"safyan_status": "optimized",
"safyan_domain": "code",
"score_before": 22,
"score_after": 78,
"score_delta": 56,
"grade_before": "F",
"grade_after": "B"
}
}
Set stream: true. Response is SSE in exact OpenAI format:
data: {"id":"sfyn-chatcmpl-...","object":"chat.completion.chunk","choices":[{"delta":{"role":"assistant"},"finish_reason":null}]}
data: {"id":"sfyn-chatcmpl-...","object":"chat.completion.chunk","choices":[{"delta":{"content":"Hello"},"finish_reason":null}]}
data: [DONE]
Change base_url to https://safyan.ai. Same optimization, Anthropic response format.
| Field | Type | Required | Description |
|---|---|---|---|
| model | string | required | safyan-auto, safyan-fast, or any model ID |
| messages | array | required | Anthropic-format messages |
| system | string | optional | System prompt (preserved alongside Safyan optimization) |
| max_tokens | integer | required | Max response tokens |
| stream | boolean | optional | Enable SSE streaming |
{
"id": "sfyn-msg-abc123...",
"type": "message",
"role": "assistant",
"content": [{ "type": "text", "text": "..." }],
"model": "claude-haiku-4-5-20251001",
"stop_reason": "end_turn",
"usage": { "input_tokens": 142, "output_tokens": 89 },
"safyan": { ... }
}
No authentication required. Returns all available models.
| Model ID | Provider | Description |
|---|---|---|
| safyan-auto | Safyan | Domain-aware routing. Full AI translation + best model selection. |
| safyan-fast | Safyan | Compile-only. Deterministic optimization, no translation AI call. Half the cost. |
| claude-sonnet-4-20250514 | Anthropic | Premium reasoning. Code, analysis, complex tasks. |
| claude-haiku-4-5-20251001 | Anthropic | Fast, efficient. General tasks. |
| gpt-4o | OpenAI | Creative, writing, image-related tasks. |
| gpt-4o-mini | OpenAI | Fast, cost-efficient. Business, simple tasks. |
| deepseek-chat | DeepSeek | Code and math reasoning. Budget fallback. |
Translate a human prompt through Safyan's 7 Cures engine. Returns the optimized prompt (not an AI response).
| Field | Type | Required | Description |
|---|---|---|---|
| text | string | required | The prompt to optimize. Max 10,000 chars. |
| mode | string | optional | lightning | standard | deep | code | creative | research | business |
| platform | string | optional | Target: chatgpt | claude | gemini | perplexity | deepseek | copilot | mistral |
| position | string | optional | intro | followup | deep | conclusion |
Score a prompt 0-100 against the 7 Cures. Instant, no AI call. Use to show users how to improve.
// Request
{ "text": "help me with code" }
// Response
{
"total": 17,
"breakdown": {
"noise": 5, // Cure #1: signal clarity (0-15)
"vagueness": 5, // Cure #2: specificity (0-15)
"constraints": 0, // Cure #3: boundaries (0-15)
"role": 0, // Cure #4: expert role (0-15)
"examples": 0, // Cure #5: references (0-10)
"focus": 15, // Cure #6: single ask (0-15)
"antipatterns": 0 // Cure #7: what NOT to do (0-15)
},
"grade": "F",
"label": "Vague"
}
Grade scale: A (80+) Expert, B (65+) Strong, C (50+) Average, D (35+) Weak, F (<35) Vague
Every proxy response includes these headers:
| Header | Example | Description |
|---|---|---|
| X-Safyan-Primitives | PRIME,LOCK,BOUND,SHAPE | Which primitives were applied |
| X-Safyan-Mode | standard | Translation mode used |
| X-Safyan-Status | optimized | optimized (full), compiled (compile-only), cached (from cache), fallback (translate failed, raw prompt sent) |
| X-Safyan-Score-Before | 22 | Original prompt score (0-100) |
| X-Safyan-Score-After | 78 | Optimized prompt score (0-100) |
| X-RateLimit-Limit | 100 | Daily request limit for your plan |
| X-RateLimit-Remaining | 73 | Requests remaining today |
| X-RateLimit-Reset | 1711843200 | Unix timestamp when limit resets (midnight UTC) |
All errors follow the format: {"error": {"message": "...", "type": "...", "code": "..."}}
| Code | HTTP | Description | Action |
|---|---|---|---|
| auth_required | 401 | Missing or invalid API key | Check your Authorization: Bearer sfk_... header |
| invalid_messages | 400 | Malformed messages array | Check message structure: each must have role (string) and content (string or array) |
| missing_user_message | 400 | No user message in the conversation | Include at least one message with role: "user" |
| MANIPULATION_DETECTED | 400 | Prompt contains deception, impersonation, or attack patterns | Safyan blocks manipulative prompts. Remove the harmful pattern. |
| rate_limit_exceeded | 429 | Daily limit reached | Wait until midnight UTC or upgrade to Pro for unlimited |
| internal_error | 500 | Server error | Retry. If persistent, contact support. |
The Anthropic proxy returns errors in Anthropic's format:
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "..."
}
}
| Plan | Proxy requests/day | Global rate | Price |
|---|---|---|---|
| Free | 100 | 100 req/min | $0 |
| Pro | Unlimited | 100 req/min | $7.99/mo |
| Lifetime | Unlimited | 100 req/min | $69 one-time |
Rate limits are tracked in-memory with daily reset at midnight UTC. The X-RateLimit-* headers are included in every response.