Auth

Bill an Agent against a subscription seat instead of an API key.

auth tells an Agent to bill a run against a subscription seat rather than an API key.

Diagram

no

yes

๐Ÿค– new Agent auth

๐Ÿ” provider registered?

โŒ throws at construction

๐Ÿ”‘ resolve once on first turn

๐ŸŒ wrap fetch with provider headers

Quick Start

  1. Pick a provider
    typescript
    import { Agent } from 'praisonai';
    
    const agent = new Agent({
      instructions: 'You are helpful',
      auth: 'claude-code',
    });
    const reply = await agent.chat('Hello');
  2. Let auth choose the model

    Omit llm and auth picks the provider’s default model, so a subscription token never ships to the wrong endpoint.


Default models

When you pass auth without an llm, the agent uses the provider’s default model.

ProviderDefault model
claude-codeanthropic/claude-sonnet-4-5
qwen-cliopenai/qwen3-coder-plus

How it works

The credentials are resolved once on the first turn, then every outgoing request is sent through a fetch wrapper that adds the provider’s headers. Existing headers on a request win, so you can still override one deliberately.

Because a subscription seat belongs to one vendor, auth also pins the default model โ€” falling back to API-key billing would charge the wrong account, so an unregistered provider fails at construction rather than at request time.

When it throws

typescript
import { Agent } from 'praisonai';

new Agent({ instructions: 'Hi', auth: 'not-a-provider' });
// Error: Unknown subscription provider 'not-a-provider'. Registered: (none).
//   A subscription store is a host concern: register one with
//   registerAuthProvider('not-a-provider', resolver).

Leaf import for bundle-sensitive callers

resolveAuth, registerAuthProvider, listAuthProviders, resetAuthProviders, and the LLMAuth, LLMAuthResolver, and LLMAuthSource types can be imported from 'praisonai', 'praisonai/llm', or the leaf module 'praisonai/llm/auth'. All three resolve to the same names โ€” PraisonAI PR #4874 moved the implementation into llm/auth.ts and re-exports it, so the public API is unchanged.

typescript
// Any of these work โ€” same names, same behaviour
import { registerAuthProvider } from 'praisonai';
import { registerAuthProvider } from 'praisonai/llm';
import { registerAuthProvider } from 'praisonai/llm/auth';

Related