For the complete documentation index, see llms.txt. This page is also available as Markdown.

Scalekit

Add per-user OAuth tool calling to your FastRouter agent with Scalekit. Gmail, GitHub, Slack, and more, with zero custom OAuth code.

What is Scalekit?

Scalekit is an SDK that gives AI agents secure, per-user access to external services like Gmail, GitHub, and Slack. It handles OAuth flows, token storage, token refresh, tool discovery, and tool execution server-side. Your agent never touches raw access tokens.

By routing your agent through FastRouter with Scalekit, you get:

  • 100+ models from OpenAI, Anthropic, Google, xAI, Meta, Groq, Mistral, and more through one endpoint

  • Observability for every request: cost, tokens, latency, and model selection tracked in real time

  • Reliability through automatic failover across providers, response caching, and intelligent routing

  • Governance with per-key budgets, rate limits, model restrictions, role-based access, and project isolation

  • Per-user OAuth with zero custom OAuth code — Scalekit manages credentials for each connected account

This guide covers FastRouter + Scalekit integration, model selection, team governance, and production feature usage.

Overview

FastRouter supports function calling out of the box. Scalekit extends that with per-user OAuth tool access, so your agent can read Gmail, create GitHub issues, or post to Slack on behalf of individual users. You can choose from 100+ connectors.

The integration is one configuration change: point the OpenAI SDK's baseURL at FastRouter. Scalekit handles OAuth token storage, tool discovery, and tool execution. Your agent never touches raw access tokens.

Sample repository: github.com/scalekit-developers/fastrouter-scalekit-demo


What you are building

FastRouter as the LLM provider. All chat completions go through FastRouter's OpenAI-compatible endpoint. Switch models by changing one environment variable.

Scalekit for tool access. listScopedTools returns per-user tool schemas ready to pass directly to FastRouter. executeTool runs each tool server-side and returns structured results.

B2B OAuth without custom OAuth code. Scalekit handles the OAuth flow, token storage, and refresh for each connected service. Your agent gets an auth link, waits for the user to authorize, and receives a verified, active connected account.

Agentic loop. The agent calls FastRouter, receives tool calls, executes them through Scalekit, and feeds results back, repeating until FastRouter returns a final answer.


Prerequisites


Clone and run the sample

1. Clone the repository and install dependencies

2. Copy the example environment file and fill in your credentials

Open .env and set these values:

SCALEKIT_CONNECTION_NAME must match the exact connection name in your Scalekit dashboard under AgentKit > Connections.

FASTROUTER_MODEL accepts any model in the FastRouter catalog that supports function calling.

3. Run the agent

4. Authorize the connection on first run

The agent prints an authorization link if the connected account is not yet active:

Open the link in your browser and complete the OAuth flow. The agent detects the callback automatically and continues.

After authorization, the agent loads tools, calls FastRouter, and prints a final answer:


How the agent works

Three pieces connect FastRouter to Scalekit tools.

1. Initialize FastRouter using the OpenAI SDK

FastRouter's API is OpenAI-compatible. Point baseURL at FastRouter and pass your FastRouter API key:

No other FastRouter-specific setup is required. The standard openai package works as-is.

2. B2B OAuth connects user accounts without custom token code

Scalekit handles the full OAuth flow. Your agent calls getOrCreateConnectedAccount to check whether the user's account is already connected, then calls getAuthorizationLink to get an auth URL if it isn't.

userVerifyUrl is where Scalekit redirects the user's browser after the OAuth flow completes (a GET request with auth_request_id and state query parameters). The sample runs a minimal HTTP server on localhost:3000 to catch that redirect, validate the state against the original value, extract the auth_request_id, and call verifyConnectedAccountUser to mark the account active:

Production callback endpoint: In a production web app, replace localhost:3000/callback with your server's callback endpoint. Scalekit redirects the browser to it with auth_request_id and state query params. Your handler must validate the state before calling verifyConnectedAccountUser to complete account activation.

3. Tool discovery returns schemas in FastRouter's expected format

listScopedTools returns only the tools the connected account has permission to use. Map each tool's input_schema to the parameters field FastRouter expects:

FastRouter uses the same function-calling format as OpenAI. No additional schema transformation is needed.

4. The agentic loop runs until the model stops requesting tools

Pass the tool list to FastRouter and execute each tool call through Scalekit until the model returns a response with no tool calls:


Customize the agent

Change the model. Set FASTROUTER_MODEL in .env to any model in the FastRouter catalog that supports function calling. The agent code stays identical regardless of which model you pick.

Model Examples

Switch to a different provider or model at any time:

No code changes or SDK swaps required. Update the model string and your agent uses the new provider.

Automatic Model Selection

Let FastRouter pick the best model for each request based on query complexity, domain, and cost:

FastRouter analyzes the input and routes to the most appropriate model from the available pool. This is the fastest way to get started without maintaining model preferences.

Explore automatic model selection

Cost-Optimized Routing with Sorting Suffixes

Append a suffix to any model to control provider selection:

Configure cost and performance routing

Flex Pricing

For batch-style agent tasks that tolerate higher latency, append :flex to access up to 50% lower token costs:

Flex routes your request to the provider's discounted inference tier. Same API key, same endpoint, same payload.

Note: Flex is not recommended for interactive agent sessions where you need low-latency responses. Use it for large batch processing, bulk email triage, or scheduled background tasks.

Compare flex pricing options

Change the connection. Set SCALEKIT_CONNECTION_NAME to any connection configured in your Scalekit dashboard:

Value
What it connects

gmail

Gmail read/send

github

Repositories, issues, pull requests

slack

Channels, messages, users

Change the prompt. Pass a prompt as a CLI argument to override the default:

Or set USER_PROMPT in .env to change the default.

Support multiple connections. Call listScopedTools with multiple connection names to give the model tools from all of them at once:

Use FastRouter-specific features. Since FastRouter is the LLM provider, you can layer on any FastRouter capability alongside Scalekit tools. For example, add tags for cost tracking, use virtual model aliases to route across model pools, or configure fallback models for resilience.


FAQs

Configuration & Setup

Can I use multiple models with the same API key?

Yes. The API key controls access and budget. The model is set via FASTROUTER_MODEL. You can switch models at any time without changing your key.

Can I use my own provider keys (BYOK)?

Yes. Set up an External Key integration in the FastRouter dashboard, then route agent traffic through it. You retain your provider's pricing and rate limits while gaining FastRouter's routing and observability layer.

Can I restrict a key to only use specific models?

Yes. When creating or editing a key, use the Select Models setting to limit which models the key can access. FastRouter rejects requests to unauthorized models.

Costs & Budgeting

What happens when a key exceeds its budget?

FastRouter blocks further requests until the budget resets (if a reset interval is configured) or an admin increases the limit. The agent receives an error response indicating the budget has been exceeded.

How do I track agent spending by team or connection?

Create separate projects for each team, issue project-scoped API keys, and use Dynamic Tags for finer-grained attribution. The dashboard breaks down costs by project, key, model, and tag.

Performance & Reliability

Does FastRouter add latency to requests?

FastRouter adds near-zero gateway overhead. For most workflows, this is negligible compared to model inference time.

Privacy & Security

Does Scalekit see my users' OAuth tokens?

Scalekit stores OAuth tokens server-side. Your agent never handles raw access tokens. Scalekit uses them to execute tools on behalf of connected accounts.

Is my request content sent to FastRouter's servers?

FastRouter acts as a pass-through gateway. Requests are routed to the model provider and responses are returned to your client. Content logging can be disabled per key for sensitive workloads — see the Disable Content Logging option in key settings.


Next steps


Last updated