Add Pay with MartLLM to your app
One balance that works in every AI app. Your users sign in with MartLLM, say how much your app may spend a month, and your app gets an API key on their account. Every request is paid from their balance, so you never front the cost of their usage and never handle their payment details.
What you get by registering your app (instead of the anonymous Connect MartLLM flow):
- Your name, logo, site and verified domain on the consent screen.
- People set a monthly allowance for your app while allowing it. They can see what your app spent and change the allowance or disconnect it any time on their Apps page.
- An optional app fee: a % you add on top of our price, paid to you.
- A place in the public app directory on martllm.com/apps once your domain is verified.
It is the same OAuth PKCE flow and the same endpoints as OpenRouter's, plus one
parameter, client_id.
1. Register your app
On Dashboard → API Keys → Apps page, open For developers and choose Add an app:
| Field | |
|---|---|
| App name | Shown on the consent screen, the user's Apps page and the directory. Up to 60 characters. |
| One line about the app | Optional, up to 200 characters. |
| Website | https:// only. The domain you verify. |
| Logo link | Optional, https://. No logo = no picture is shown. |
| Return addresses | 1 to 10, one per line. Users are only ever sent back to one of these (exact match; a query string is allowed). https://, or http://localhost with any port while you build. |
| Your fee | 0 to 50% on top of our price (two decimals at most). |
You get a Client ID. It is public: put it in your front-end code.
Verify your domain
The app card shows a DNS record. Add it at your DNS provider, then choose Check now:
| Name | Type | Value |
|---|---|---|
your site's host, without www. |
TXT |
martllm-verify=mv_… (copy it from the card) |
Verified apps show "Verified owner of your domain" on the consent screen and can be listed in the directory. Changing the website removes the verification until you check the new domain.
2. Add the button
This is a complete browser example: no server and no library. It sends the user to MartLLM, takes them back, trades the one-time code for their key and makes a request with it.
<button id="connect">Pay with MartLLM</button>
<pre id="out"></pre>
<script type="module">
const CLIENT_ID = 'YOUR_CLIENT_ID'; // from the Apps page
const CALLBACK = location.origin + location.pathname; // one of your return addresses
const b64url = (bytes) =>
btoa(String.fromCharCode(...new Uint8Array(bytes)))
.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
// 1. Send the user to MartLLM with a fresh PKCE challenge.
document.getElementById('connect').onclick = async () => {
const verifier = b64url(crypto.getRandomValues(new Uint8Array(32)));
const challenge = b64url(await crypto.subtle.digest('SHA-256', new TextEncoder().encode(verifier)));
const state = b64url(crypto.getRandomValues(new Uint8Array(16)));
sessionStorage.setItem('martllm_pkce', JSON.stringify({ verifier, state }));
const url = new URL('https://martllm.com/auth');
url.search = new URLSearchParams({
client_id: CLIENT_ID,
callback_url: CALLBACK,
code_challenge: challenge,
code_challenge_method: 'S256',
state,
});
location.assign(url);
};
// 2. Back from MartLLM: trade the code for the user's key (works once, for 10 minutes).
const params = new URLSearchParams(location.search);
const saved = JSON.parse(sessionStorage.getItem('martllm_pkce') || 'null');
if (params.get('code') && saved && params.get('state') === saved.state) {
sessionStorage.removeItem('martllm_pkce');
history.replaceState(null, '', CALLBACK);
const res = await fetch('https://martllm.com/api/v1/auth/keys', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ code: params.get('code'), code_verifier: saved.verifier, code_challenge_method: 'S256' }),
});
if (!res.ok) throw new Error((await res.json()).error?.message || res.statusText);
const { key } = await res.json(); // ull_…: keep it like a password
localStorage.setItem('martllm_key', key);
}
// 3. Use it: any OpenAI-compatible call, paid from the user's balance.
const key = localStorage.getItem('martllm_key');
if (key) {
const r = await fetch('https://api.martllm.com/v1/chat/completions', {
method: 'POST',
headers: {
Authorization: `Bearer ${key}`,
'Content-Type': 'application/json',
'HTTP-Referer': location.origin, // counts your app on the apps ranking
'X-Title': 'My App',
},
body: JSON.stringify({
model: 'deepseek/deepseek-v4-flash',
messages: [{ role: 'user', content: 'Say hello in five words.' }],
}),
});
document.getElementById('out').textContent = (await r.json()).choices?.[0]?.message?.content ?? '';
}
</script>
On a server, keep the key server-side instead of in localStorage, and do the
exchange in step 2 from your server (the endpoint answers both).
The consent screen
https://martllm.com/auth takes:
| Parameter | |
|---|---|
client_id |
Your Client ID. |
callback_url |
One of your return addresses. Leave it out to show the code on screen for the user to paste into your app. |
code_challenge |
Base64url SHA-256 of your code_verifier (43 to 128 random characters you keep). Required. |
code_challenge_method |
S256. Required. |
state |
Optional. Sent back unchanged with the code. |
The user sees your app, what it can do, its price (our price, or our price plus
your fee) and a monthly allowance they can set (on by default, $10). On
Allow they come back to callback_url?code=…&state=…. On Cancel
nothing is sent anywhere.
A wrong or removed client_id, or a callback_url that is not one of your
return addresses, stops at an error page: nothing is shared and the user is
never sent to that address.
3. The allowance
The monthly allowance is the key's own spending limit for the calendar month
(UTC), checked on every request. Your fee counts toward it. When a request
would go over it, the API answers 402 with code key_spend_cap_exceeded and the
user's balance is not touched. Ask the user to raise the allowance on their
Apps page.
A picture, video or music job holds its price plus your fee before it starts, and both the allowance and the balance are checked against that whole amount. The job is never billed above what it held: it is charged what it cost plus your fee on that, and the rest goes back at once. A job that fails is not charged, and no fee is taken.
When the user disconnects your app, its key is turned off at once: every
following request answers 401. Send them through the button again to
reconnect.
4. Your fee
- You set it when you register (0 to 50%). It is added on top of what the request costs on MartLLM. MartLLM's own fee stays 0%.
- People see it before they allow your app ("MartLLM prices + 10%") and on every request in their Activity ("+ $0.0012 to My App").
- If you raise it later, people who already connected keep paying the % they agreed to. New connections ask with the new %. If you lower it, everyone pays the lower one from then on.
- It is paid to your MartLLM account like seller earnings: in your balance at once, available to pay out after the earnings hold (14 days while your seller account is under 30 days old or has earned under $500, 7 days after), on Seller → Payouts, by the same payout methods as sellers (including MartLLM credit).
- If a request is refunded (for example a seller caught serving a different model), its fee goes back to the user too.
Removing an app
Remove on the Apps page stops sign-in with that Client ID. People who already connected keep their keys, with no fee from then on. A suspended app can't be removed.
If MartLLM suspends your app
MartLLM can suspend an app that misleads people or misuses their balance. While it is suspended:
- The consent screen refuses it, naming it. Nothing is shared with it.
- Every request with a key it got answers
403with codeapp_suspendedand a message naming the app. Nothing is charged and no fee is earned. - Your Apps page says it is suspended.
MartLLM can also take an app out of the public directory without suspending it: it keeps working for everyone who connects it. Write to [email protected] to talk about either.
Differences from OpenRouter
client_idis MartLLM's: without it the flow is the same as OpenRouter's (Connect MartLLM).code_challengeis required and onlyS256is accepted.- The return address must be one you registered.