Migrate from direct model provider API usage
Replace your Anthropic, OpenAI, or OpenRouter calls with Agent Platform. In our (limited) tests we found that this adds around 2 to 3 seconds of latency to all responses.
| Previous | With Agent Platform |
|---|---|
| Store a provider API key in your backend | Store AP_API_KEY in your backend |
| Create one chat or responses request | Create or reuse a session, then create a run |
| Pass prior messages each time | Reuse the same session_id |
| Stream provider tokens | Stream run_event records |
| Call tools from your own integration layer | Use gateway-backed actions inside runs or action_invocations |
| Build your own request log | Inspect runs and events in /dashboard/runs |
Why Agent Platform
- One key instead of separate provider and integration credentials
- Workspace scoping and audit through the platform gateway
- Durable event timelines for debugging and replay
- Same execution model across the CLI, dashboard, and API
Agent Platform doesn't replace every provider call in your system. If a backend job only needs one known action, call action_invocations directly and skip sessions entirely.
Minimal replacement pattern
- Replace your provider client with a thin Agent Platform client.
- Create a session when a user starts a new conversation or task.
- Create runs inside that session for each prompt.
- Use
wait: truefor request/response handlers andstream: truefor interactive UIs. - Use
action_invocationsfor deterministic calls that don't need model reasoning.
Example
Before (Anthropic)
await anthropic.messages.create({
model: "claude-sonnet-4-5",
messages: [{ role: "user", content: "Summarize open incidents." }],
});After (Agent Platform)
const session = await apFetch("/sessions", {
method: "POST",
body: JSON.stringify({ title: "Incident review" }),
});
const run = await apFetch(`/sessions/${session.id}/runs`, {
method: "POST",
body: JSON.stringify({
input: [
{
role: "user",
content: [{ type: "input_text", text: "Summarize open incidents." }],
},
],
wait: true,
}),
});When not to use a run
Skip sessions and runs when you already know the exact action to call and only need the gateway result. Call POST /v1/action_invocations directly instead.