Quickstart
Connect a local /v1/chat/completions endpoint to an external testing platform through spectral-bridge.
Start a local endpoint
If you already have a service exposing POST /v1/chat/completions, you can follow along with that instead.
Just note its local endpoint (e.g., http://192.168.1.100:8000).
Install FastAPI:
pip install "fastapi[standard]"
Save this echo bot as echo_bot.py. It mirrors the last user message back as the assistant reply, which is enough to validate the connection before switching to your real system.
from fastapi import FastAPI, Requestfrom fastapi.responses import JSONResponseapp = FastAPI()@app.post("/v1/chat/completions")async def chat(messages: list[dict]):last = messages[-1]["content"]return JSONResponse(content={"choices": [{"message": {"role": "assistant", "content": last}}]})
Start it:
fastapi run echo_bot.py --port 8000
The server listens on http://localhost:8000.
Connect to the testing platform
Install spectral-bridge
pip install "spectral-bridge[pass-through]"
Set your API key
The testing platform provides an API key that authenticates the relay client with their relay server. Set it as an environment variable:
export SPECTRAL_BRIDGE_API_KEY=<your-api-key>
Connect to the relay
Replace --relay-url with the URL from your testing platform. If your endpoint runs on a different host or port, update --target accordingly.
spectral-bridge start \--relay-url <relay-server-url> \--adapter pass-through \--target <local-target-url>
Replace values in angle brackets with your specific configuration:
<relay-server-url>: the WebSocket URL of the relay server provided by your testing platform (e.g.,wss://bridge.spectral.principled.app).<local-target-url>: the URL of your local endpoint (e.g.,http://localhost:8000,http://192.168.1.100:8000).
Once the connection is established, leave it running as long as you want to allow the testing platform to send requests to your AI system through spectral-bridge. Once you terminate it, the connection is closed and the testing platform can no longer reach your system.
Next steps
- Pass-through Adapter: full reference for the passthrough adapter.
- Custom Adapter: write your own adapter.
- Protocol Reference: the relay protocol specification.