Skip to content

ravirdp/prism-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Prism API Examples

Prism is an AI API proxy that intelligently routes your prompts to the best model based on a quality mode you choose. Send requests in the same OpenAI format you already use — just change the base URL.

One-line integration:

- base_url="https://api.openai.com/v1"
+ base_url="https://api.prism.ssimplifi.com/v1"

Prism handles model selection, automatic failover, session memory, and cost tracking — so you don't have to.


What is Prism?

Prism sits between your app and AI providers (Anthropic, OpenAI, Google). You pick a quality mode and Prism picks the right model for your specific query type:

Mode Best for Markup
eco High-volume, simple tasks 15%
balanced General use 20%
sport Complex reasoning, code 30%

Prism classifies each query (simple / code / reasoning / complex) and routes it accordingly. A simple query in Eco mode gets Gemini Flash. A complex reasoning task in Sport mode gets Claude Opus. The quality floor ensures even Eco never sends a hard task to a weak model.

Response headers tell you exactly what happened:

  • X-Prism-Model — which model was used
  • X-Prism-Cost — cost in USD cents
  • X-Prism-Task-Type — how Prism classified your query
  • X-Prism-Failover — whether a failover occurred

Quickstart

1. Get your API key

Sign up at prism.ssimplifi.com → your key is shown once on the signup page. It looks like: prism_sk_abc123...

2. Make your first call

curl https://api.prism.ssimplifi.com/v1/chat/completions \
  -H "Authorization: Bearer YOUR_PRISM_KEY" \
  -H "X-Prism-Mode: eco" \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [{"role": "user", "content": "Hello! What is Prism?"}]
  }'

That's it. No model name needed — Prism picks the right one.

3. Use with the OpenAI SDK

Python:

from openai import OpenAI

client = OpenAI(
    api_key="YOUR_PRISM_KEY",
    base_url="https://api.prism.ssimplifi.com/v1",
    default_headers={"X-Prism-Mode": "balanced"}
)

response = client.chat.completions.create(
    model="prism",  # ignored — Prism selects the model
    messages=[{"role": "user", "content": "Explain recursion briefly."}]
)
print(response.choices[0].message.content)

TypeScript/Node:

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "YOUR_PRISM_KEY",
  baseURL: "https://api.prism.ssimplifi.com/v1",
  defaultHeaders: { "X-Prism-Mode": "balanced" },
});

const response = await client.chat.completions.create({
  model: "prism",
  messages: [{ role: "user", content: "Explain recursion briefly." }],
});
console.log(response.choices[0].message.content);

Examples

File Description
python/basic_chat.py Basic chat completion in Eco mode
python/streaming.py Streaming response in Balanced mode
python/session_memory.py Multi-turn conversation with session memory
python/error_handling.py Handling errors and failover detection
python/cost_comparison.py Compare costs across Eco / Balanced / Sport
typescript/basic_chat.ts Basic chat completion in Eco mode
typescript/streaming.ts Streaming response in Balanced mode
typescript/session_memory.ts Multi-turn conversation with session memory
typescript/error_handling.ts Handling errors and failover detection
typescript/cost_comparison.ts Compare costs across Eco / Balanced / Sport
curl/examples.sh All examples as curl commands

Free Tier

The free tier lets you try Prism without a credit card:

  • 50K input / 10K output tokens per day
  • Eco mode only
  • No streaming
  • 5 messages per session

Upgrade by topping up your balance at prism.ssimplifi.com.


Links


Error Reference

All errors follow a consistent format:

{
  "error": {
    "type": "insufficient_balance",
    "message": "Your balance is too low to complete this request."
  }
}
Error type Meaning
invalid_api_key Key is missing, malformed, or revoked
missing_mode_header X-Prism-Mode header not included
insufficient_balance Balance too low (top up in dashboard)
free_tier_limit Daily token limit reached
rate_limited Too many requests
provider_error Upstream provider failed (failover attempted)
invalid_request Malformed request body

About

Code examples for the Prism AI API proxy — Python, TypeScript, and curl

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors