Skip to content

Latest commit

 

History

History
136 lines (104 loc) · 3.35 KB

File metadata and controls

136 lines (104 loc) · 3.35 KB

f5-ai-sec-api-simulator

Deterministic API simulator for testing:

  • Connection Assistant decisioning (V1 direct vs V2 proxy-required)
  • Proxy parser behavior (json, sse, ndjson, multipart)
  • End-to-end flow: Red Team -> Proxy -> Target Endpoint

This service intentionally focuses on response shape and streaming behavior first.

Scenarios

  • POST /sim/json/basic
    • Standard JSON payload with message field.
    • Good for direct YAML generation tests.
  • POST /sim/json/chunked-array
    • Returns a JSON array of token-like chunks:
      • [{"role":"assistant","content":"..."}, ...]
    • Good for forcing V2/proxy-required decisions.
  • POST /sim/stream/sse
    • Server-Sent Events (text/event-stream) with data: JSON frames.
  • POST /sim/stream/ndjson
    • NDJSON streaming (application/x-ndjson) one JSON object per line.
  • POST /sim/stream/multipart
    • Multipart mixed stream (multipart/mixed) with JSON parts.

Utility endpoints:

  • GET /
  • GET /healthz
  • GET /scenarios

Request Body

All simulation endpoints accept:

{
  "prompt": "hello world",
  "total_chunks": 12,
  "chunk_delay_ms": 30,
  "top_k": "all",
  "metadata": {}
}

Fields:

  • prompt: input text used to build deterministic response content.
  • total_chunks: approximate number of chunks emitted for chunked/streaming scenarios.
  • chunk_delay_ms: delay between emitted chunks (streaming endpoints).
  • top_k: optional passthrough field for shape testing.
  • metadata: optional passthrough object.

Run Locally

python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
uvicorn app.main:app --host 0.0.0.0 --port 10000 --reload

Quick Tests

curl -sS http://127.0.0.1:10000/healthz
curl -sS -X POST http://127.0.0.1:10000/sim/json/basic \
  -H 'Content-Type: application/json' \
  -d '{"prompt":"Who is in the company?"}'
curl -sS -X POST http://127.0.0.1:10000/sim/json/chunked-array \
  -H 'Content-Type: application/json' \
  -d '{"prompt":"stream this in json chunks","total_chunks":16}'
curl -N -X POST http://127.0.0.1:10000/sim/stream/sse \
  -H 'Content-Type: application/json' \
  -d '{"prompt":"sse please","total_chunks":8,"chunk_delay_ms":40}'
curl -N -X POST http://127.0.0.1:10000/sim/stream/ndjson \
  -H 'Content-Type: application/json' \
  -d '{"prompt":"ndjson please","total_chunks":8,"chunk_delay_ms":40}'
curl -N -X POST http://127.0.0.1:10000/sim/stream/multipart \
  -H 'Content-Type: application/json' \
  -d '{"prompt":"multipart please","total_chunks":8,"chunk_delay_ms":40}'

Deploy To Render

This repo includes:

  • Dockerfile
  • render.yaml

Create a new Render Web Service from this repo and use Docker deploy. Health check path: /healthz.

Proxy Integration

Example profile definitions are in:

  • profiles.proxy.examples.json

Load into f5-ai-sec-proxy with runtime profile APIs:

curl -X POST https://<your-proxy>/profiles/upload \
  -H 'X-Profile-Admin-Token: <admin-token-if-enabled>' \
  -F "replace_existing=false" \
  -F "file=@profiles.proxy.examples.json"

Call proxy with selected profile:

curl -X POST https://<your-proxy>/ask \
  -H 'Content-Type: application/json' \
  -d '{
    "prompt": "test chunk behavior",
    "external_metadata": {
      "proxy_profile": "sim_json_chunked_array"
    }
  }'