Token4S Model API
Combine academic search with model inference in Research Mode, research scripts, and AI tools
Token4S provides a model API. Connect it as a custom model in Ai4Scholar, or use it in your own scripts to organize academic search results from the Ai4Scholar API.
Choose your integration
| What you want to do | Where to start |
|---|---|
| Use your own model key in Ai4Scholar Research Mode | Follow “Connect to Research Mode” below |
| Search for papers and summarize abstracts in a script | Use the Python example below |
| Combine the services in Dify or another AI tool | Add Ai4Scholar as an academic data tool and Token4S as the model provider |
The two sites manage accounts, API keys, and balances separately. Your Ai4Scholar key is for academic data and tool APIs; your Token4S key is for model APIs. With a custom model in Research Mode, the provider charges for model usage, while tools still use Ai4Scholar credits. Ai4Scholar built-in models do not require a Token4S account.
Connect to Research Mode
- Visit Token4S, sign in, create an API key, and check its available models and balance.
- Return to Ai4Scholar and open Settings → Model settings → Token4S.
- Click Connect Token4S. The provider name, Base URL, and API format are already filled in; expand Advanced settings to change them.
- Enter your own Token4S API key and fetch the available models. Select a model that supports tool calling, or enter its model ID manually.
- Save the provider and test the connection. After a successful test, select the model for a new conversation.
| Setting | Preset value |
|---|---|
| Name | Token4S |
| Base URL | https://token4s.com/v1 |
| API format | OpenAI Chat Completions |
| API Key | Your personal key from Token4S |
| Model ID | A model available to your key that supports the selected API format |
The preset only fills in connection details. It does not create an account, purchase credits, or make a model request. A model appearing in the list still needs to pass the Research Mode tool calling test. Connection tests incur a small amount of model usage.
Academic search + model summaries
A typical workflow: search with Ai4Scholar → extract titles and abstracts → summarize with Token4S → retain paper IDs and links for verification.
This example sends only the paper information returned by search. Install requests, then set AI4SCHOLAR_API_KEY, TOKEN4S_API_KEY, and TOKEN4S_MODEL in your environment. Choose a currently available Token4S model that supports Chat Completions.
import json
import os
import requests
# Academic search uses the Ai4Scholar key.
search = requests.get(
"https://ai4scholar.net/graph/v1/paper/search",
headers={"Authorization": f"Bearer {os.environ['AI4SCHOLAR_API_KEY']}"},
params={
"query": "retrieval augmented generation evaluation",
"limit": 5,
"fields": "paperId,title,abstract,url,year",
},
timeout=60,
)
search.raise_for_status()
papers = search.json().get("data", [])
if not papers:
raise SystemExit("No papers found. Try a different query.")
# Model inference uses a separate Token4S key.
completion = requests.post(
"https://token4s.com/v1/chat/completions",
headers={"Authorization": f"Bearer {os.environ['TOKEN4S_API_KEY']}"},
json={
"model": os.environ["TOKEN4S_MODEL"],
"messages": [
{
"role": "system",
"content": (
"Summarize research themes using only the supplied abstracts. "
"Cite paper IDs and URLs. Flag missing abstracts; "
"do not infer findings from titles alone."
),
},
{"role": "user", "content": json.dumps(papers, ensure_ascii=False)},
],
},
timeout=120,
)
completion.raise_for_status()
print(completion.json()["choices"][0]["message"]["content"])Academic search and model inference are billed separately. Check summaries against the original papers; a model response is not a substitute for evidence. Consult each site's console for available models, pricing, and balances.
Continue integrating
- Ai4Scholar Open API: academic data endpoints and authentication.
- Plugins & Integrations: connect Dify, MCP, OpenClaw, and other tools.
- Explore Token4S: view model services and your usage.