Peerwave

Peerwave

Discover

Download

Docs

Discord

Authentication

Peerwave offers a unique API model where users pay for access. Users authenticate with the Peerwave network and your application makes cross-origin calls on their behalf. Anonymous users can try applications without signing up, with seamless upgrade paths when needed.

Anonymous Access

The quickest way to try Peerwave is with anonymous access. No API keys, no signup - just start making requests. When your user has exceeded their anonymous credit balance, you will receive a redirect link in the location header to log them in. After they log in, they will be redirected back to your application.

Try Anonymous Chat Request

fetch("https://api.peerwave.ai/api/chat", { method: "POST", headers: { "Content-Type": "application/json", "Redirect": window.location.pathname + "?codeblock=anonymous-chat" }, body: JSON.stringify({ "model": "cheapest", "messages": [ { "role": "user", "content": "How are you doing?" } ] }) }).then((response) => { if (!response.ok && response.status === 402) { const location = response.headers.get("Location"); if (location) { window.location.href = location; } } return response.json(); })

Try making an anonymous request. If you're out of anonymous credits, you'll be redirected to authenticate.

Anonymous Limits: Anonymous users get a limited credit balance that refreshes periodically to prevent abuse. When credits are exhausted, they'll be redirected to sign up and return to your application seamlessly.

Manual Authentication

If you want to trigger a user sign in, you can simply redirect them to the third-party authorization endpoint which is similar to an OAuth flow. When they are finished logging in, they will be sent back to your application with a JWT token in the URL fragment.

Step 1: Redirect user for authorization

Redirect users to our authorization endpoint with your app's callback URL:

const currentPage = window.location.toString(); window.location.href = `https://api.peerwave.ai/api/third-party/auth?redirect=${currentPage}`;

Step 2: Handle authorization response

After the user logs in (if needed) and consents to your application, they'll be redirected back with a JWT in the URL fragment:

https://yourapp.com/#token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

Step 3: Use JWT Token

Parse the token from the URL fragment and include it in your API requests via the Authorization header:

// Extract token from URL fragment const hashParams = new URLSearchParams(window.location.hash.substring(1)); const credentials = hashParams.get("token"); // Use token in API requests fetch("https://api.peerwave.ai/api/chat", { method: "POST", headers: { "Content-Type": "application/json", "Redirect": "/", "Authorization": credentials, }, body: JSON.stringify({ "model": "cheapest", "messages": [ { "role": "user", "content": "Hi!" }, ], }), })

Security Note: JWT tokens are IP-bound and can only be used from the user's browser. This ensures tokens cannot be stored and misused on servers. Users will only see a consent page once per application.