openapi: 3.0.3 info: title: PSTN2 API description: | Distributed telecommunications protocol API for fraud prevention, direct routing, and enhanced emergency services. **Features:** - Real-time caller ID authentication - Direct peer-to-peer routing - End-to-end encryption - Emergency location services - Number Discovery (regulator numbering list + Range Holder query, no central database) **Base URL:** `https://api.{your-cp}.com/pstn2/v1` **Request signing:** Signatures are carried in the JSON request body (`signature` field, Ed25519 over the message body plus timestamp, per SPECIFICATION.md §4.1). There is no signature HTTP header. version: 1.1.0 contact: name: PSTN2 Support url: https://pstn2.org email: nick.holland@8x8.com license: name: CC0 1.0 Universal (public domain) url: https://creativecommons.org/publicdomain/zero/1.0/ servers: - url: https://api.cp1.example.com/pstn2/v1 description: Example CP1 Server - url: https://api.cp2.example.com/pstn2/v1 description: Example CP2 Server # Requests are authenticated by body-level Ed25519 signatures (and mutual TLS # for PSAPs), not by an OpenAPI security scheme. security: [] tags: - name: Authentication description: Caller ID verification endpoints - name: Routing description: Direct routing discovery - name: Emergency description: Emergency services location - name: Number Discovery description: Who holds this number? Range Holder query with redirect for ported numbers (SPECIFICATION.md §9) - name: Numbering List description: Regulator numbering list (Ofcom S1-S9 + Range Holder URL), downloaded and cached by every CP paths: /auth/verify: post: tags: - Authentication summary: Verify caller ID (Direct Query) description: | Verify that a call originated from the claiming CP. Used by recipient CP to authenticate inbound calls in real-time. **Performance Target:** < 100ms response time operationId: verifyCall requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/CallVerificationRequest' examples: basic: $ref: '#/components/examples/VerificationRequestBasic' responses: '200': description: | Verification result. If this CP no longer holds the caller ID, the body is a NotHeldResponse (`result: not_held`, `cache.invalidate`); the client purges its cache, rediscovers the holder from the Range Holder (SPECIFICATION.md §9.3) and retries there. content: application/json: schema: oneOf: - $ref: '#/components/schemas/CallVerificationResponse' - $ref: '#/components/schemas/NotHeldResponse' examples: verified: $ref: '#/components/examples/VerificationResponseVerified' '400': description: Invalid request format or timestamp out of range content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '404': description: Call not found (potential fraud) content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' examples: notFound: $ref: '#/components/examples/CallNotFound' '401': $ref: '#/components/responses/Unauthorized' '429': $ref: '#/components/responses/RateLimited' '500': $ref: '#/components/responses/InternalError' /routing/request: post: tags: - Routing summary: Request direct routing description: | Request connection details for direct peer-to-peer media. Includes capability negotiation and key exchange. **Performance Target:** < 200ms response time operationId: requestRouting requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/RoutingRequest' examples: audio: $ref: '#/components/examples/RoutingRequestAudio' video: $ref: '#/components/examples/RoutingRequestVideo' responses: '200': description: Routing accepted content: application/json: schema: $ref: '#/components/schemas/RoutingResponse' examples: accepted: $ref: '#/components/examples/RoutingResponseAccepted' '503': description: Service unavailable (capacity/maintenance) content: application/json: schema: $ref: '#/components/schemas/RoutingRejection' '400': description: Invalid request format or timestamp out of range content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '401': $ref: '#/components/responses/Unauthorized' '404': description: Destination number not held by this CP (prefer a 200 NotHeldResponse with cache.invalidate) content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' /emergency/location: post: tags: - Emergency summary: Query emergency location description: | Retrieve real-time location for emergency call. Restricted to authenticated PSAPs only. **Rate Limit:** 10 req/sec per PSAP **Retention:** Location data retained no longer than 24 hours after call end (see MAP data-retention policy) operationId: getEmergencyLocation requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/EmergencyLocationRequest' responses: '200': description: Location available content: application/json: schema: $ref: '#/components/schemas/EmergencyLocationResponse' examples: gps: $ref: '#/components/examples/EmergencyLocationGPS' '400': description: Invalid request format or timestamp out of range content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '404': description: Location unavailable content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '401': $ref: '#/components/responses/Unauthorized' '403': description: Not authorized (not a valid PSAP) content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' /numbers/{e164digits}: get: tags: - Number Discovery summary: Who holds this number? description: | Ask a CP about one number. Query the Range Holder first (found in the numbering list), or the cached holder. The Range Holder answers `held`, or `redirect` to the CP the number was ported to. A CP that is not the Range Holder and no longer serves the number answers `not_held` with a cache invalidation. A plain GET with no body, so responses are cacheable and static-hostable. **Performance Target:** < 50ms per hop operationId: discoverNumber parameters: - name: e164digits in: path required: true description: E.164 number without the leading `+` schema: type: string pattern: '^[1-9]\d{1,14}$' example: '441614960123' responses: '200': description: Discovery result content: application/json: schema: $ref: '#/components/schemas/DiscoveryResponse' examples: held: $ref: '#/components/examples/DiscoveryHeld' redirect: $ref: '#/components/examples/DiscoveryRedirect' notHeld: $ref: '#/components/examples/DiscoveryNotHeld' '404': description: Number not in service or unknown to this CP. Body optional. '429': $ref: '#/components/responses/RateLimited' /keys: get: tags: - Number Discovery summary: Public signing keys of this CP description: Ed25519 public keys used to verify this CP's signed responses (`kid`). operationId: getKeys responses: '200': description: Key set content: application/json: schema: $ref: '#/components/schemas/KeySet' /numbering-list.json: servers: - url: https://numbering.regulator.example description: Regulator (Ofcom) or an approved mirror get: tags: - Numbering List summary: Download the numbering list description: | Ofcom S1-S9 numbering data augmented with each Range Holder's PSTN2 URL. Download at least daily and cache locally; never query per call. Match numbers by longest prefix. operationId: getNumberingList parameters: - name: If-None-Match in: header required: false schema: type: string responses: '200': description: Current list headers: ETag: schema: type: string content: application/json: schema: $ref: '#/components/schemas/NumberingList' '304': description: Local copy is current components: # NOTE: CP request signing is body-level, not header-level. Each signed # request schema carries a required `signature` field (Ed25519 over the # message body plus timestamp, per SPECIFICATION.md §4.1), so it is not # modelled as an OpenAPI security scheme. # PSAP requests to /emergency/location are additionally authenticated # with TLS client certificates (mutual TLS) at the transport layer. schemas: PhoneNumber: type: string pattern: '^\+[1-9]\d{1,14}$' description: E.164 formatted phone number example: '+441234567890' RCPID: type: string pattern: '^CP[12]-[A-Z]{2}-\d{4}$' description: Range-CP-ID (e.g., CP1-UK-0001) example: 'CP1-UK-0001' CallReference: type: string format: uuid description: UUID v4 call reference example: '550e8400-e29b-41d4-a716-446655440000' Timestamp: type: string format: date-time description: ISO 8601 timestamp with timezone example: '2025-11-30T21:30:00.000Z' Base64String: type: string format: byte description: Base64 encoded binary data CallVerificationRequest: type: object required: - messageId - timestamp - version - requestingCP - callerID - calledID - callReference - signature properties: messageId: type: string format: uuid timestamp: $ref: '#/components/schemas/Timestamp' version: type: string enum: ['1.1'] requestingCP: $ref: '#/components/schemas/RCPID' callerID: $ref: '#/components/schemas/PhoneNumber' calledID: $ref: '#/components/schemas/PhoneNumber' callReference: $ref: '#/components/schemas/CallReference' signature: $ref: '#/components/schemas/Base64String' CallVerificationResponse: type: object required: - verified - callReference - timestamp properties: verified: type: boolean callReference: $ref: '#/components/schemas/CallReference' callerName: type: string example: 'John Smith' callerOrg: type: string example: 'ACME Corp' callPurpose: type: string example: 'Account verification' trustLevel: type: string enum: [low, medium, high, verified] branding: $ref: '#/components/schemas/BrandingInfo' timestamp: $ref: '#/components/schemas/Timestamp' signature: $ref: '#/components/schemas/Base64String' BrandingInfo: type: object properties: logo: type: string format: uri example: 'https://cdn.acme.com/logo.png' backgroundColor: type: string pattern: '^#[0-9A-Fa-f]{6}$' example: '#0066cc' textColor: type: string pattern: '^#[0-9A-Fa-f]{6}$' example: '#ffffff' displayName: type: string maxLength: 50 example: 'ACME Support' callPurpose: type: string maxLength: 100 example: 'Account Security Alert' CacheControl: type: object description: | Caching instruction carried by any PSTN2 response (SPECIFICATION.md §9.4-9.5). properties: ttl: type: integer minimum: 0 description: Seconds the client may cache the number -> holder answer example: 86400 invalidate: type: boolean description: Purge the cached entry and rediscover from the Range Holder scope: type: string enum: [number, block] default: number NotHeldResponse: type: object description: | HTTP 200 from a CP that no longer holds the number. Purge the cache and rediscover from the Range Holder. required: - result - cache properties: verified: type: boolean enum: [false] result: type: string enum: [not_held] callReference: $ref: '#/components/schemas/CallReference' cache: $ref: '#/components/schemas/CacheControl' timestamp: $ref: '#/components/schemas/Timestamp' RoutingRequest: type: object required: - messageId - timestamp - version - requestingCP - callerID - destinationNumber - callReference - mediaCapabilities - publicKey - signature properties: messageId: type: string format: uuid timestamp: $ref: '#/components/schemas/Timestamp' version: type: string example: '1.1' requestingCP: $ref: '#/components/schemas/RCPID' callerID: $ref: '#/components/schemas/PhoneNumber' destinationNumber: $ref: '#/components/schemas/PhoneNumber' callReference: $ref: '#/components/schemas/CallReference' mediaCapabilities: $ref: '#/components/schemas/MediaCapabilities' publicKey: $ref: '#/components/schemas/Base64String' branding: $ref: '#/components/schemas/BrandingInfo' signature: $ref: '#/components/schemas/Base64String' MediaCapabilities: type: object required: - codecs - encryption properties: codecs: type: array items: type: string enum: [opus, g722, pcmu, pcma, g729] example: ['opus', 'g722', 'pcmu'] encryption: type: array items: type: string enum: [srtp-aes256, srtp-aes128] example: ['srtp-aes256'] video: type: boolean default: false maxBandwidth: type: integer description: Maximum bandwidth in bps example: 128000 RoutingResponse: type: object required: - accepted - callReference - timestamp properties: accepted: type: boolean callReference: $ref: '#/components/schemas/CallReference' connectionDetails: $ref: '#/components/schemas/ConnectionDetails' agreedCapabilities: $ref: '#/components/schemas/MediaCapabilities' timestamp: $ref: '#/components/schemas/Timestamp' signature: $ref: '#/components/schemas/Base64String' ConnectionDetails: type: object required: - fqdn - port - protocol properties: fqdn: type: string format: hostname example: 'media.cp2.example.com' ipv4: type: string format: ipv4 example: '203.0.113.42' ipv6: type: string format: ipv6 example: '2001:db8::42' port: type: integer minimum: 1024 maximum: 65535 example: 5060 protocol: type: string enum: [udp, tcp, tls] publicKey: $ref: '#/components/schemas/Base64String' RoutingRejection: type: object required: - accepted - reason - timestamp properties: accepted: type: boolean enum: [false] reason: type: string enum: [capacity_exceeded, maintenance, unsupported_codec] fallbackToTraditional: type: boolean default: true retryAfter: type: integer description: Seconds until retry timestamp: $ref: '#/components/schemas/Timestamp' EmergencyLocationRequest: type: object required: - messageId - timestamp - version - requestingPSAP - callerID - callReference - signature properties: messageId: type: string format: uuid timestamp: $ref: '#/components/schemas/Timestamp' version: type: string example: '1.1' requestingPSAP: type: string pattern: '^[A-Z]{2}-[0-9]{3}-[A-Z0-9-]+$' example: 'UK-999-LONDON-01' callerID: $ref: '#/components/schemas/PhoneNumber' callReference: $ref: '#/components/schemas/CallReference' signature: $ref: '#/components/schemas/Base64String' EmergencyLocationResponse: type: object required: - callReference - location - timestamp properties: callReference: $ref: '#/components/schemas/CallReference' location: $ref: '#/components/schemas/LocationData' address: $ref: '#/components/schemas/AddressData' additionalInfo: type: object properties: cellTowerId: type: string wifiAccessPoints: type: array items: type: string lastUpdated: $ref: '#/components/schemas/Timestamp' timestamp: $ref: '#/components/schemas/Timestamp' signature: $ref: '#/components/schemas/Base64String' LocationData: type: object required: - latitude - longitude - accuracy properties: latitude: type: number format: double minimum: -90 maximum: 90 example: 51.5074 longitude: type: number format: double minimum: -180 maximum: 180 example: -0.1278 accuracy: type: number format: float description: Accuracy in meters example: 15.0 altitude: type: number format: float description: Altitude in meters source: type: string enum: [gps, wifi, cell, user, billing] AddressData: type: object properties: street: type: string example: '10 Downing Street' city: type: string example: 'London' postcode: type: string example: 'SW1A 2AA' country: type: string pattern: '^[A-Z]{2}$' description: ISO 3166-1 alpha-2 country code example: 'GB' CpRef: type: object required: - cpId - url properties: cpId: $ref: '#/components/schemas/RCPID' cpName: type: string example: 'Bravo Networks' url: type: string format: uri description: Base URL of the CP's PSTN2 API (endpoints are {url}/pstn2/v1/...) example: 'https://pstn2.bravo-networks.example' DiscoveryResponse: type: object required: - version - result - number properties: version: type: string example: '1.1' result: type: string enum: [held, redirect, not_held] number: $ref: '#/components/schemas/PhoneNumber' holder: $ref: '#/components/schemas/CpRef' ported: type: boolean description: (held) true when the holder is not the Range Holder portedTo: $ref: '#/components/schemas/CpRef' cache: $ref: '#/components/schemas/CacheControl' issued: $ref: '#/components/schemas/Timestamp' kid: type: string description: Signing key id (see /keys) signature: $ref: '#/components/schemas/Base64String' KeySet: type: object required: - cpId - keys properties: cpId: $ref: '#/components/schemas/RCPID' keys: type: array items: type: object required: [kid, algorithm, publicKey] properties: kid: type: string algorithm: type: string enum: [ed25519] publicKey: $ref: '#/components/schemas/Base64String' validFrom: $ref: '#/components/schemas/Timestamp' validTo: $ref: '#/components/schemas/Timestamp' NumberingList: type: object required: - listVersion - blocks properties: listVersion: type: string publisher: type: string example: 'Ofcom' source: type: string blocks: type: array items: $ref: '#/components/schemas/NumberingBlock' NumberingBlock: type: object required: - prefix - numberLength - status - cpId properties: prefix: type: string pattern: '^[1-9]\d{0,14}$' description: E.164 digits common to every number in the block example: '441614960' display: type: string example: '0161 496 0xxx' numberLength: type: integer example: 12 status: type: string enum: [Allocated, Free, Reserved, Protected] cpId: $ref: '#/components/schemas/RCPID' cpName: type: string rangeHolderUrl: type: string format: uri description: Absent = Range Holder does not participate (use traditional PSTN) ErrorResponse: type: object required: - error properties: error: type: object required: - code - message - timestamp properties: code: type: string enum: - call_not_found - invalid_signature - capacity_exceeded - unsupported_codec - number_not_found - hop_limit_exceeded - loop_detected - location_unavailable - unauthorized_psap - timeout - rate_limit_exceeded - invalid_request - internal_error message: type: string timestamp: $ref: '#/components/schemas/Timestamp' requestId: type: string format: uuid responses: Unauthorized: description: Unauthorized - Invalid signature or credentials content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' RateLimited: description: Too many requests headers: Retry-After: schema: type: integer description: Seconds until retry allowed content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' InternalError: description: Internal server error content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' examples: DiscoveryHeld: value: version: '1.1' result: held number: '+441614960123' holder: cpId: CP1-UK-0102 cpName: Bravo Networks url: https://pstn2.bravo-networks.example ported: false cache: ttl: 86400 issued: '2026-10-06T09:00:00Z' kid: bravo-2026-10 signature: 'kV6QbUqP3vD0aXk2y8z1Zr4sWm9tFh7nLc5eJg0oBdQ=' DiscoveryRedirect: value: version: '1.1' result: redirect number: '+441134960456' portedTo: cpId: CP1-UK-0102 cpName: Bravo Networks url: https://pstn2.bravo-networks.example cache: ttl: 86400 issued: '2026-10-06T09:00:00Z' kid: charlie-2026-10 signature: 'kV6QbUqP3vD0aXk2y8z1Zr4sWm9tFh7nLc5eJg0oBdQ=' DiscoveryNotHeld: value: version: '1.1' result: not_held number: '+441134960456' cache: invalidate: true scope: number issued: '2026-10-06T09:00:00Z' kid: bravo-2026-10 signature: 'kV6QbUqP3vD0aXk2y8z1Zr4sWm9tFh7nLc5eJg0oBdQ=' VerificationRequestBasic: summary: Basic verification request value: messageId: '550e8400-e29b-41d4-a716-446655440000' timestamp: '2025-11-30T21:30:00.000Z' version: '1.1' requestingCP: 'CP1-UK-0002' callerID: '+441234567890' calledID: '+447700900123' callReference: '3f2504e0-4f89-41d3-9a0c-0305e82c3301' signature: 'base64-encoded-signature-here' VerificationResponseVerified: summary: Call verified successfully value: verified: true callReference: '3f2504e0-4f89-41d3-9a0c-0305e82c3301' callerName: 'John Smith' callerOrg: 'ACME Corp' callPurpose: 'Account verification' trustLevel: 'verified' branding: displayName: 'ACME Support' logo: 'https://cdn.acme.com/logo.png' backgroundColor: '#0066cc' textColor: '#ffffff' timestamp: '2025-11-30T21:30:00.050Z' signature: 'base64-signature' CallNotFound: summary: Call not found (potential fraud) value: error: code: 'call_not_found' message: 'No matching call record found' timestamp: '2025-11-30T21:30:00.050Z' requestId: '123e4567-e89b-12d3-a456-426614174000' RoutingRequestAudio: summary: Audio call routing request value: messageId: '123e4567-e89b-12d3-a456-426614174000' timestamp: '2025-11-30T21:30:00.000Z' version: '1.1' requestingCP: 'CP1-UK-0001' callerID: '+441234567890' destinationNumber: '+447700900123' callReference: '9b2f8c44-1d3e-4f6a-8b5c-2e7d9a0f4c11' mediaCapabilities: codecs: ['opus', 'g722'] encryption: ['srtp-aes256'] video: false publicKey: 'base64-ed25519-key' signature: 'base64-signature' RoutingRequestVideo: summary: Video call routing request value: messageId: '123e4567-e89b-12d3-a456-426614174000' timestamp: '2025-11-30T21:30:00.000Z' version: '1.1' requestingCP: 'CP1-UK-0001' callerID: '+441234567890' destinationNumber: '+447700900123' callReference: 'e58ed763-928c-4155-bee9-fdbaaadc15f3' mediaCapabilities: codecs: ['opus', 'h264'] encryption: ['srtp-aes256'] video: true maxBandwidth: 2000000 publicKey: 'base64-ed25519-key' signature: 'base64-signature' RoutingResponseAccepted: summary: Routing accepted value: accepted: true callReference: '9b2f8c44-1d3e-4f6a-8b5c-2e7d9a0f4c11' connectionDetails: fqdn: 'media.cp2.example.com' ipv4: '203.0.113.42' ipv6: '2001:db8::42' port: 5060 protocol: 'udp' publicKey: 'base64-ed25519-key' agreedCapabilities: codecs: ['opus'] encryption: ['srtp-aes256'] video: false timestamp: '2025-11-30T21:30:00.150Z' signature: 'base64-signature' EmergencyLocationGPS: summary: GPS location for emergency call value: callReference: 'f47ac10b-58cc-4372-a567-0e02b2c3d479' location: latitude: 51.5074 longitude: -0.1278 accuracy: 15.0 altitude: 42.5 source: 'gps' address: street: '10 Downing Street' city: 'London' postcode: 'SW1A 2AA' country: 'GB' additionalInfo: cellTowerId: '234-10-12345-67890' wifiAccessPoints: ['AA:BB:CC:DD:EE:FF', '11:22:33:44:55:66'] lastUpdated: '2025-11-30T21:29:58.000Z' timestamp: '2025-11-30T21:30:00.000Z' signature: 'base64-signature'