buildApiClient function creates a type-safe HTTP client for interacting with the AgentStack platform API. This client enables you to manage contexts, generate tokens with permissions, match model providers, and list connectors.
Initialization
Create an API client by callingbuildApiClient with configuration options:
Configuration Options
baseUrl(required): The base URL of your AgentStack server instancefetch(optional): Custom fetch implementation. Required in Node.js < 18 or environments without global fetch support. Useful for adding authentication headers or custom request handling.
Example: Authenticated Client
In many applications, you’ll want to add authentication headers to requests:API Methods
createContext(providerId: string)
Creates a new agent context. Contexts are isolated workspaces where agents can store files, vector stores, and other context-specific data.
Parameters:
providerId: The ID of the provider to associate with this context
Promise<CreateContextResponse>
createContextToken(params: CreateContextTokenParams)
Generates a context token with specific permissions. Context tokens are used to grant agents access to platform resources through the Platform API extension.
Parameters:
contextId: The ID of the context to create a token forglobalPermissions: Permissions that apply across all contextscontextPermissions: Permissions specific to this context
Promise<{ token: ContextToken; contextId: string }>
Permissions
Permissions control what resources agents can access. There are two types:Global Permissions
Apply across all contexts and control access to platform-wide resources:llm: Access to LLM providers. Can be['*']for all providers or an array of specific provider IDsembeddings: Access to embedding providers. Same format asllmmodel_providers: Read/write access to model provider configurationsa2a_proxy: Access to A2A proxy servicesproviders: Access to provider managementprovider_variables: Access to provider environment variablescontexts: Access to context managementmcp_providers: Access to MCP providersmcp_tools: Access to MCP toolsmcp_proxy: Access to MCP proxyconnectors: Access to connector managementfeedback: Ability to submit feedback
Context Permissions
Apply only to the specific context:files: File operations (read,write,extract, or*for all)vector_stores: Vector store operations (read,write, or*for all)context_data: Context metadata operations (read,write, or*for all)
matchProviders(params: MatchProvidersParams)
Finds model providers that match specified criteria. This is typically used when fulfilling LLM or embedding service extension demands.
Parameters:
suggestedModels: Array of preferred model IDs, ornullto match any modelcapability: EitherModelCapability.LlmorModelCapability.EmbeddingscoreCutoff: Minimum match score (0.0 to 1.0). Higher values require better matches.
Promise<ModelProviderMatch>
listConnectors()
Lists all available connectors in the platform. Connectors enable agents to integrate with external services and APIs.
Returns: Promise<ListConnectorsResponse>
Common Usage Patterns
Creating a Context and Token for an Agent
The most common pattern is creating a context and generating a token with appropriate permissions:Fulfilling LLM Demands
When an agent requests LLM access, usematchProviders to find suitable models:
Type Safety
All API methods are fully typed with TypeScript and use Zod schemas for runtime validation. Response data is automatically validated against these schemas, ensuring type safety and catching API contract changes at runtime.Next Steps
- Extensions - Learn how to use the API client with extension fulfillments
- Examples - See complete integration examples