API Proxy
The API Proxy is the single web entry point into SBN Media. SBN Anywhere and SBN Video clients, the SBN Media dashboard, and other applications all connect through it. It receives web requests, forwards them to the right service, and returns the response.
Overview
The API Proxy turns incoming web requests into messages for the services that do the work, then relays the result back. It is the only SBN Media service that normally needs to be reachable from outside the host - everything else sits behind it.
It also serves the SBN Media dashboard and the API documentation, and it is the connection point a browser uses to start a live video session.
- Runs: When configured; at most one per host. A host that serves video or web clients needs one.
- Required: Yes, for any host that serves clients. Without it, SBN Anywhere and SBN Video clients cannot reach SBN Media.
- Depends on: NATS, which it uses to reach the other services.
Configuration
The API Proxy is configured under the apiproxy namespace. View the defaults with ./sbn-media config eject and set host-specific overrides in sbn-media.local.yaml.
| Setting | Default | Description |
|---|---|---|
apiproxy.port | 8081 | The port the API Proxy listens on. |
apiproxy.address | empty | The address to bind to. Empty listens on all addresses. |
apiproxy.protocol | http | http or https. Use https in production. |
apiproxy.publishedUrl | empty | The URL clients use to reach the API Proxy. Defaults to protocol://address:port. |
apiproxy.allowOrigins | * | Which web origins may call the API Proxy. In production, set this to the origins of the applications that use it - for example your SBN Anywhere or SBN Video front end - rather than *. |
apiproxy.requireToken | true | Require a valid token on requests. Tokens are checked against the API Engine. |
apiproxy.adminToken | empty | Protects the administrative routes. If it is not set, those routes are unavailable. |
apiproxy.prometheusToken | empty | Token required to read Prometheus metrics. |
apiproxy.maxBodySize | 10485760 | Largest request body accepted, in bytes (10 MB). |
apiproxy.routes | see below | Turns individual feature routes on or off. |
Routes
Each feature of the API Proxy is a route that can be turned on or off under apiproxy.routes. A route that is off is not available. Routes marked "admin" require apiproxy.adminToken to be set and supplied by the caller.
| Route | Default | Enables |
|---|---|---|
static | on | The SBN Media dashboard and sample client pages. |
swagger | on | The API documentation at /api/docs. |
webrtc | on | Live video connections for SBN Video clients. |
recording | on | Access to recorded video, and the download of routing call recordings and transcripts (see Downloading captures and recordings). |
classify | on | Object-detection endpoints. |
sceneChange | on | Scene-change detection endpoints. |
reid | on | Re-identification queries. |
device | on | The device registry. |
apsl | on | Action-plan script endpoints. |
textToSpeech | on | Listing the available text-to-speech voices. |
foresight | on | Foresight invite links. |
watchdog | on | Service control - start, stop, restart, health (admin). |
log | on | Live and historical logs (admin). |
pprof | off | Performance profiling, for diagnostics (admin). |
signalTrace | off | Download raw call captures, for diagnostics (admin). |
mediaCapture | off | List and download raw camera captures, for diagnostics (admin). A client can also fetch its own capture. |
partnerLog | off | The partner log search API, including the packet capture download for a call. Requires a partner credential. |
partnerLogUI | off | The partner log search web application. Requires partnerLog. |
fileserver | off | A local file server, for testing only. |
Example:
After changing these settings in sbn-media.local.yaml, reload the configuration for them to take effect. Changing the listen address or port requires restarting the service.
Downloading captures and recordings
The API Proxy streams captures and recordings to the caller as downloads. It does not hold them itself: the service that owns the data prepares the file and the API Proxy relays it, so large downloads do not depend on the size of a single message.
Routing call recordings and transcripts
A call handled by the routing service can leave a recording and a transcript. Both are fetched through the recording route, using a bearer token in the Authorization header:
GET /api/routing-captures/{dealer}/{recordingId}returns the call recording as an MP4 file, named<recordingId>.mp4, as an attachment.GET /api/routing-captures/{dealer}/{recordingId}/transcriptreturns the transcript of the same call.
The caller must be allowed to download recordings (the recording-download action) for the dealer. The recording is served only when a catalogue record for it is stored; a recording that has no stored record is answered as not found, including a recording that was split into several parts. The transcript is read without the catalogue record.
| Response | Meaning |
|---|---|
| 200 | The file follows. |
| 400 | The dealer or the recording id is not valid. |
| 401 | No valid bearer token was supplied. The credential is checked before the id, so a request without one is refused whatever the id. |
| 404 | The recording or transcript does not exist, the caller has no grant for it, the request was refused, or the backend could not answer. The body is empty in every case. |
The 404 is deliberately the same for a missing grant and for a missing recording, so a caller cannot probe which recordings exist for another dealer. A caller who receives a 404 for a recording that should exist should check that the caller holds the recording-download action for that dealer, and that the call was recorded.
Raw call and camera captures
These are diagnostic downloads for support work. They are off by default and need the admin token.
signalTraceserves the captured legs of a call under/signal-trace./signal-trace/{traceId}downloads a capture as a.tarfile,/signal-trace/{traceId}/legslists the captured legs of one call, and/signal-trace/{traceId}/alldownloads every leg of the call as a single.tarfile. An unknown call answers 404.mediaCaptureserves camera captures./media-capturelists them, and/media-capture/{captureId}downloads one. A client that holds its own capture identifier can fetch it at/media-capture/self/{captureId}without the admin token. These routes are answered by the camera loader.
Partner packet capture
When partnerLog is on, a partner credential can download the packet capture of one of its own calls at GET /api/v1/partner/log/pcap/{tranId}. It is authenticated and scoped to the partner's tenant in the same way as the partner log search. A call that has no capture, or that the partner may not see, is answered as not found.
FAQ
SBN Video clients cannot connect. What should I check?
First confirm the API Proxy is running and reachable - check it in the dashboard, or open its address in a browser. Then confirm the port (8081 by default) is open on the network, and that apiproxy.allowOrigins includes the origin of the client application (for example SBN Anywhere or SBN Video). If the service will not start, run it in the foreground with sbn-media service exec apiproxy -ld to see the startup error.
How do I secure the API Proxy?
Use https for apiproxy.protocol, set apiproxy.allowOrigins to the origins of the applications that use it (such as SBN Anywhere or SBN Video) instead of *, keep apiproxy.requireToken set to true, and set a strong apiproxy.adminToken. Leave the diagnostic routes (pprof, signalTrace, mediaCapture, fileserver) off unless you are actively using them.
Why am I getting an unauthorized (401) response?
apiproxy.requireToken is on, so every request must carry a valid token, which the API Proxy checks against the API Engine. The administrative routes (service control, logs, profiling, signal trace, media capture) need the admin token as well - confirm apiproxy.adminToken is set and that the caller is supplying it. The routing call recording and transcript downloads need a bearer token in the Authorization header, and the partner routes need a partner credential; a request without one is refused before the recording id is looked at.
Why does a recording download answer 404 when the recording exists?
The download answers 404 for every case where it will not serve the file, so that a caller cannot tell a missing recording from one it may not see. Check that the caller holds the recording-download action for that dealer, that the recording has a stored catalogue record, and that the dealer in the URL is the dealer that owns the recording.
Do I need an API Proxy on every host?
You can run at most one per host, and you need at least one that clients can reach. In a multi-host setup it is common for each host to run its own so that a client can connect through any of them. A common production configuration places the API Proxy in a DMZ on several servers that load-balance incoming requests; the requests are then carried out by the other services behind them.
Related pages
- SBN Media Overview (
SBN-Media/overview) - Deploying SBN Media (
SBN-Media/deployment) - Watchdog (
SBN-Media/Platform/watchdog) - Firewall (
SBN-Media/Configuration/firewall)