OpenAI Proxy Anthropic Proxy Models Translate Score Headers Error Codes Rate Limits

OpenAI-Compatible Proxy

Drop-in replacement. Change baseURL to https://safyan.ai/v1. Every prompt is optimized before reaching the AI.

POST /v1/chat/completions

Request Body

FieldTypeRequiredDescription
modelstringrequiredsafyan-auto (best model picked), safyan-fast (compile-only, half cost), or any model ID
messagesarrayrequiredArray of {role, content} objects. Max 200 messages, 100K chars per message.
streambooleanoptionalEnable SSE streaming. Default: false
max_tokensintegeroptionalMax response tokens. Default: 4096

Response

{
  "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"
  }
}

Streaming

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]

Anthropic-Compatible Proxy

Change base_url to https://safyan.ai. Same optimization, Anthropic response format.

POST /v1/messages

Request Body

FieldTypeRequiredDescription
modelstringrequiredsafyan-auto, safyan-fast, or any model ID
messagesarrayrequiredAnthropic-format messages
systemstringoptionalSystem prompt (preserved alongside Safyan optimization)
max_tokensintegerrequiredMax response tokens
streambooleanoptionalEnable SSE streaming

Response

{
  "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": { ... }
}

Models

GET /v1/models

No authentication required. Returns all available models.

Model IDProviderDescription
safyan-autoSafyanDomain-aware routing. Full AI translation + best model selection.
safyan-fastSafyanCompile-only. Deterministic optimization, no translation AI call. Half the cost.
claude-sonnet-4-20250514AnthropicPremium reasoning. Code, analysis, complex tasks.
claude-haiku-4-5-20251001AnthropicFast, efficient. General tasks.
gpt-4oOpenAICreative, writing, image-related tasks.
gpt-4o-miniOpenAIFast, cost-efficient. Business, simple tasks.
deepseek-chatDeepSeekCode and math reasoning. Budget fallback.

Direct Translation

POST /api/translate

Translate a human prompt through Safyan's 7 Cures engine. Returns the optimized prompt (not an AI response).

FieldTypeRequiredDescription
textstringrequiredThe prompt to optimize. Max 10,000 chars.
modestringoptionallightning | standard | deep | code | creative | research | business
platformstringoptionalTarget: chatgpt | claude | gemini | perplexity | deepseek | copilot | mistral
positionstringoptionalintro | followup | deep | conclusion

Prompt Scoring

POST /api/translate/score

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

Response Headers

Every proxy response includes these headers:

HeaderExampleDescription
X-Safyan-PrimitivesPRIME,LOCK,BOUND,SHAPEWhich primitives were applied
X-Safyan-ModestandardTranslation mode used
X-Safyan-Statusoptimizedoptimized (full), compiled (compile-only), cached (from cache), fallback (translate failed, raw prompt sent)
X-Safyan-Score-Before22Original prompt score (0-100)
X-Safyan-Score-After78Optimized prompt score (0-100)
X-RateLimit-Limit100Daily request limit for your plan
X-RateLimit-Remaining73Requests remaining today
X-RateLimit-Reset1711843200Unix timestamp when limit resets (midnight UTC)

Error Codes

All errors follow the format: {"error": {"message": "...", "type": "...", "code": "..."}}

CodeHTTPDescriptionAction
auth_required401Missing or invalid API keyCheck your Authorization: Bearer sfk_... header
invalid_messages400Malformed messages arrayCheck message structure: each must have role (string) and content (string or array)
missing_user_message400No user message in the conversationInclude at least one message with role: "user"
MANIPULATION_DETECTED400Prompt contains deception, impersonation, or attack patternsSafyan blocks manipulative prompts. Remove the harmful pattern.
rate_limit_exceeded429Daily limit reachedWait until midnight UTC or upgrade to Pro for unlimited
internal_error500Server errorRetry. If persistent, contact support.

Anthropic format

The Anthropic proxy returns errors in Anthropic's format:

{
  "type": "error",
  "error": {
    "type": "invalid_request_error",
    "message": "..."
  }
}

Rate Limits

PlanProxy requests/dayGlobal ratePrice
Free100100 req/min$0
ProUnlimited100 req/min$7.99/mo
LifetimeUnlimited100 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.