parezenparezenDocs
Get free X-ray

Documentation

DocsThe stackQuickstartRun the auditHosted gatewaySelf-hostingCloud platformsSDKs and frameworksFail-open patternLever guideHow savings are verifiedData handlingAPI referencePR cost check setup
Docs/Fail-open pattern

Fail-open pattern

App-side retry if Parezen is down. A budget hard stop stays a hard stop. A lapsed licence switches to pass-through and does not error traffic.

When it runs

Planned. Fail-open lives in your app, because Parezen cannot forward a call while it is down. The design retries directly with your own provider key on a connection error, a timeout or a 5xx. Do not retry on a 4xx. A budget hard stop is designed as a 4xx. Bypassing it would defeat the control. Billing is designed never to return an error on production traffic.

If a licence lapses, the design is 30 days of grace with alerts, then pass-through: requests would be forwarded unchanged, while optimisation and paid features pause. Data export is designed to keep working. This behaviour is not deployed.

Example only. Bypassed calls are not routed, recorded in the ledger or budget-checked. Do not bypass a 4xx. A budget hard stop must hold. Billing never returns an error on production traffic.

Example

Example only
Node
// Example only. Bypassed calls are not routed, recorded or budget-checked. Do not bypass a budget hard stop.
import OpenAI from "openai";

const viaParezen = new OpenAI({
  baseURL: "https://api.parezen.com/v1",
  apiKey: process.env.PAREZEN_API_KEY,
  timeout: 10_000,
  maxRetries: 0,
});
const direct = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });

export async function chat(params) {
  try {
    return await viaParezen.chat.completions.create(params);
  } catch (err) {
    const parezenDown = err instanceof OpenAI.APIConnectionError || (err.status ?? 0) >= 500;
    if (!parezenDown) throw err; // a 4xx, including a budget hard stop, must not be bypassed
    return direct.chat.completions.create(params);
  }
}
Python
# Example only. Bypassed calls are not routed, recorded or budget-checked. Do not bypass a budget hard stop.
import os
import openai
from openai import OpenAI

via_parezen = OpenAI(
    base_url="https://api.parezen.com/v1",
    api_key=os.environ["PAREZEN_API_KEY"],
    timeout=10,
    max_retries=0,
)
direct = OpenAI(api_key=os.environ["OPENAI_API_KEY"])

def chat(**params):
    try:
        return via_parezen.chat.completions.create(**params)
    except (openai.APIConnectionError, openai.InternalServerError):
        return direct.chat.completions.create(**params)

Example only. Bypassed calls are not routed, recorded in the ledger or budget-checked. Do not bypass a 4xx. A budget hard stop must hold. Billing never returns an error on production traffic.

Self-hosted and local Docker use http://localhost:3002/v1. A private address such as https://gateway.internal/v1 is the same pattern behind your load balancer.

Example only
Node
// Example only. Bypassed calls are not routed, recorded or budget-checked. Do not bypass a budget hard stop.
import OpenAI from "openai";

const viaParezen = new OpenAI({
  baseURL: "http://localhost:3002/v1",
  apiKey: process.env.PAREZEN_API_KEY,
  timeout: 10_000,
  maxRetries: 0,
});
const direct = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });

export async function chat(params) {
  try {
    return await viaParezen.chat.completions.create(params);
  } catch (err) {
    const parezenDown = err instanceof OpenAI.APIConnectionError || (err.status ?? 0) >= 500;
    if (!parezenDown) throw err; // a 4xx, including a budget hard stop, must not be bypassed
    return direct.chat.completions.create(params);
  }
}
Python
# Example only. Bypassed calls are not routed, recorded or budget-checked. Do not bypass a budget hard stop.
import os
import openai
from openai import OpenAI

via_parezen = OpenAI(
    base_url="http://localhost:3002/v1",
    api_key=os.environ["PAREZEN_API_KEY"],
    timeout=10,
    max_retries=0,
)
direct = OpenAI(api_key=os.environ["OPENAI_API_KEY"])

def chat(**params):
    try:
        return via_parezen.chat.completions.create(**params)
    except (openai.APIConnectionError, openai.InternalServerError):
        return direct.chat.completions.create(**params)

Example only. Bypassed calls are not routed, recorded in the ledger or budget-checked. Do not bypass a 4xx. A budget hard stop must hold. Billing never returns an error on production traffic.

On this page
  • When it runs
  • Example