Developer documentation
Build with
ShareMyTokens
Send a request with a share-link key or call your connected providers through one Account API.
Quick start{
"model": "smt/auto",
"messages": [
{ "role": "user", "content": "Hello" }
]
}Quick start
Authentication
For OpenAI-compatible requests, send your share-link key in the Authorization header. Keep your key secret — never expose it in client-side code.
Authorization: Bearer YOUR_SHARE_LINK_API_KEY
Claude Code gateway
The public Claude Code gateway is disabled. This example shows the hosted ShareMyTokens configuration for technical review. Public availability depends on Anthropic’s approval for the shared-billing setup.
How requests flow
- The host enables API access on an eligible Anthropic claimable link. The signed-in guest claims it and generates a link-scoped ShareMyTokens key in the chat’s API panel.
- Claude Code uses the gateway base URL and the ShareMyTokens key. It adds
/v1/messagesor/v1/messages/count_tokensto that URL for the relevant request. - ShareMyTokens validates the key and checks whether the link is active. For generation it checks the remaining daily budget, if configured, and the total token budget. It sends the approved request to Anthropic with the host’s provider key and streams the response when the CLI requests streaming. Anthropic bills the host’s account. The same link budget covers browser chat and API use.
Hosted PowerShell example for technical review
If the hosted gateway is enabled, the recipient will replace YOUR_LINK_ID with the ID from their claimed link and enter its ShareMyTokens link key at the hidden prompt.
$env:ANTHROPIC_BASE_URL = "https://api.sharemytokens.com/v1/share/YOUR_LINK_ID/claude"
$env:CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS = "1"
$env:CLAUDE_CODE_AUTO_MODE_SERVER = "0"
$key = Read-Host "Paste your ShareMyTokens link key" -AsSecureString
$env:ANTHROPIC_AUTH_TOKEN = [System.Net.NetworkCredential]::new("", $key).Password
Remove-Variable key
if ($env:ANTHROPIC_AUTH_TOKEN) { claude }In our local test, the official CLI sent a prompt and received a reply. We asked it to remember “Saturn,” reopened the conversation, and confirmed it could recall the word. See the test write-up and release status.
Account API
- Connect your provider keys under API Keys, then open Settings → Account API to generate an account key.
- Copy the base URL and send the account key as
Authorization: Bearer YOUR_ACCOUNT_KEY. - Call
GET /modelsunder the base URL for example models from your connected providers, or send a text request toPOST /chat/completions.
Choose a provider and model
Keep the same Account API key and base URL. Change model to switch providers. Connect the corresponding provider key in API Keys first.
| Provider | Example model IDs |
|---|---|
| OpenAI | openai/gpt-4o-miniopenai/gpt-4o |
| Anthropic | anthropic/claude-sonnet-4-6 |
| Gemini | gemini/gemini-2.5-flashgemini/gemini-2.5-pro |
| Mistral | mistral/mistral-small-latestmistral/mistral-large-latest |
| OpenRouter | openrouter/auto |
| ShareMyTokens Auto | smt/auto |
These are examples. Use GET /v1/account/models to see examples for the providers you’ve connected. Your provider account determines which models you can call.
Example request with Claude
Send this JSON to POST /v1/account/chat/completions with your Account API key as a Bearer token. To use another provider, replace the model ID with one from the table.
{
"model": "anthropic/claude-sonnet-4-6",
"messages": [{"role": "user", "content": "Reply only OK."}],
"max_tokens": 16
}For a specific model through OpenRouter, prefix its full OpenRouter model ID with openrouter/. For example, openrouter/openai/gpt-4o-mini uses your OpenRouter key. openai/gpt-4o-mini uses your direct OpenAI key.
Automatically choose GPT or Claude
Set model to smt/auto to use your connected OpenAI and Anthropic keys. Simple prompts go to GPT-4o Mini. Longer prompts and requests such as debugging or detailed analysis go to Claude Sonnet when both keys are connected. With one key connected, Auto uses that provider.
// JavaScript SDK
const reply = await account.chat({ model: "smt/auto", messages })
console.log(reply.model, reply.text)
# Python SDK
reply = account.chat(model="smt/auto", messages=messages)
print(reply["model"], reply["text"])Auto sends one provider request and returns the provider-qualified model in the response. Send the conversation history in messages if you want the next model to have the same context.
Switch providers by changing model, for example to anthropic/claude-sonnet-4-6 or openrouter/auto. Account API requests are billed to your connected provider and don’t draw from a guest link’s budget. The endpoint supports non-streaming text chat.
API reference
Use the full endpoint shown in API access for your link.
/v1/share/:sessionId/chat/completionsOpenAI-compatible chat completion/v1/share/:sessionId/messagesAnthropic Messages requestTroubleshooting
- 401 Unauthorized
- Copy the current key again and use the endpoint from the same API panel. Replacing a key invalidates the previous one.
- 403 Forbidden
- Check whether the link expired, was revoked, or has API access turned off. For the Account API, check that your provider key is saved.
- 429 Too Many Requests
- Check the link’s token budget and any daily limit. If the request rate limit was reached, wait for it to reset before retrying.
- Failed to connect
- Use the HTTPS endpoint copied from the API panel and check that your device can reach
api.sharemytokens.com.
SDKs
JavaScript / TypeScript
Install the official SDK from npm. Requires Node.js 18 or later.
npm install @sharemytokens/sdkPython
Install the official SDK from PyPI. Requires Python 3.10 or later.
pip install sharemytokens-sdkHandle errors in the Python SDK
HTTP errors raise ShareMyTokensError with a status attribute. Use the troubleshooting guide to decide how to respond.
from urllib.error import URLError
from sharemytokens import ShareMyTokensError
try:
reply = client.chat(messages=[{"role": "user", "content": "Reply only OK."}])
print(reply["text"])
except ShareMyTokensError as error:
print(f"API error {error.status}: {error}")
except (URLError, TimeoutError):
print("Could not reach the API. Check the endpoint and connection.")Use createAccountClient with the base URL in Settings or createShareLinkClient with the full endpoint shown in a claimed chat.
import { createShareLinkClient } from "@sharemytokens/sdk"
const client = createShareLinkClient({
endpoint: process.env.SHARE_LINK_ENDPOINT,
apiKey: process.env.SHARE_LINK_API_KEY,
})
const reply = await client.chat({
messages: [{ role: "user", content: "Reply only OK." }],
maxTokens: 16,
})
console.log(reply.text)