Resources
Resources are installable API endpoints, LLM integrations, and third-party service connections that scripts and templates can invoke. Resources provide standardized access to external services through OpenAPI 3.0 specifications, enabling type-safe integration with authentication, rate limiting, and usage tracking.
Syntax
Creating a Resource
Resource Structure
Resource Types
Mirra supports four resource types, each optimized for specific integration patterns.
API
apiStandard HTTP APIs with defined methods, authentication, and request/response schemas. API resources expose RESTful endpoints for data retrieval, manipulation, and service integration.
LLM
llmLarge Language Model endpoints for chat completion, text generation, and AI-powered processing. LLM resources provide standardized access to language models with token counting and cost tracking.
LLM resources are treated as standard API endpoints. To create a chat UI with subdomain deployment, bundle your LLM resource in a Template.
Script
scriptServerless functions deployed to the Mirra platform that can be invoked as resources. Script resources enable custom logic and data processing within the Mirra ecosystem.
Integration
integrationThird-party service integrations with OAuth 2.0 or complex authentication flows. Integration resources handle token management, refresh logic, and service-specific authentication patterns.
Description
Resources provide the foundation for external service integration within Mirra. Each resource encapsulates an API endpoint, authentication mechanism, and method definitions in a standardized format that Scripts and Templates can invoke.
All resources require a valid OpenAPI 3.0 specification, which the platform uses for automatic documentation generation, request/response validation, and SDK client generation. This specification-driven approach ensures type safety and clear contracts between resource providers and consumers.
OpenAPI Specification
Resources must include a complete OpenAPI 3.0 specification defining all endpoints, parameters, request bodies, and response schemas. The platform validates incoming requests against this specification and generates interactive documentation for resource consumers.
A minimal OpenAPI specification includes:
The OpenAPI specification provides four critical capabilities:
- Auto-generated documentation - Interactive API documentation for resource consumers
- Type safety - Request and response validation against defined schemas
- SDK generation - Automatic client library generation for multiple languages
- Clear contracts - Explicit interface definitions between providers and consumers
Authentication Methods
Resources support five authentication mechanisms, each configured through the authentication field and optional authConfig object.
noneNo authentication required. Use for public APIs or resources with custom authentication logic.
api_keyAPI key authentication via header or query parameter. Specify the header name and location in
authConfig.bearerBearer token authentication using the Authorization header. Commonly used for JWT tokens and OAuth 2.0 access tokens.
basicHTTP Basic authentication with username and password. Credentials are base64-encoded in the Authorization header.
oauth2OAuth 2.0 authentication flow with authorization URL, token URL, and scopes. The platform handles token refresh and expiration.
Method Definitions
Each resource method defines an HTTP operation with parameters, request body schema, response schema, and optional cost tracking.
Method definitions support all standard HTTP methods (GET, POST, PUT, PATCH, DELETE) and include path parameters using curly brace syntax: /users/{userId}.
Rate Limiting
Resources can define rate limits to control usage and prevent abuse. Rate limits specify the maximum number of requests allowed within a time window.
Supported time windows:
1m- One minute1h- One hour1d- One day
When a rate limit is exceeded, the platform returns a 429 Too Many Requests response with a Retry-After header indicating when the next request can be made.
Examples
Creating an API Resource
This example creates a cryptocurrency price API resource with API key authentication and pay-per-call pricing.
Request
Response
The resource is created in draft status and must be published before it appears in the marketplace.
Creating an LLM Resource
This example creates an OpenAI GPT-4 resource with bearer token authentication for chat completion.
Request
To create a chat UI with subdomain deployment (e.g., mychat.username.getmirra.app), bundle your LLM resource in a Template.
Installing a Resource
Users install resources to their account before invoking methods. Installation creates an installation record and prepares the resource for authentication.
Request
Response
The isAuthenticated field indicates whether the user has provided credentials. Resources requiring authentication must be authenticated before use.
Authenticating a Resource
After installation, users provide credentials for resources requiring authentication. The platform securely stores credentials and injects them into API requests.
Request
Credential Formats
- API Key
- OAuth 2.0
- Basic Auth
Tracking Usage Metrics
Resource consumers can track their usage and costs per installation. The usage endpoint returns call counts, costs, and recent activity.
Request
Response
Viewing Resource Metrics
Resource creators can view aggregated metrics across all users, including total users, calls, revenue, and ratings.
Request
Response
Publishing to Marketplace
Resources must be published to appear in the marketplace and become available for installation. Publishing validates the resource configuration and makes it discoverable.
Request
Publishing Requirements
- Valid name and description
- At least one method defined
- Valid OpenAPI 3.0 specification
- All method schemas validated
To unpublish a resource and remove it from the marketplace:
Unpublishing prevents new installations but does not affect existing installations.
Pricing Models
Resources support four pricing models to monetize API access and service usage.
Free
freeNo cost for resource usage. Suitable for open APIs, promotional resources, or community-contributed integrations.
Pay-Per-Call
pay-per-callCharges a fixed price per method invocation. Users pay only for actual usage with no recurring fees.
Subscription
subscriptionCharges a recurring monthly fee for unlimited access. Suitable for high-volume use cases with predictable costs.
Tiered
tieredOffers multiple subscription tiers with included call quotas and overage pricing. Provides flexibility for different usage levels.
Troubleshooting
Authentication Failures
When resource authentication fails, verify the following:
- Credentials match the format expected by the authentication type
- Authentication type in credentials matches the resource configuration
- OAuth 2.0 tokens have not expired (check
expiresAtfield) - API keys have the necessary permissions for the requested operations
- Bearer tokens are valid and not revoked
For OAuth 2.0 resources, the platform automatically refreshes expired tokens using the refresh token. If refresh fails, re-authenticate the resource with new credentials.
Rate Limit Errors
When encountering 429 Too Many Requests responses:
- Implement exponential backoff and retry logic in your scripts
- Check the
Retry-Afterheader for the next available request time - Consider upgrading to a higher pricing tier with increased limits
- Batch multiple operations into single requests where possible
- Cache frequently accessed data to reduce API calls
Method Not Found Errors
When a method cannot be invoked:
- Verify the method name matches the resource definition exactly
- Confirm the resource is published and available in the marketplace
- Check that the user has installed and authenticated the resource
- Ensure the method is included in the resource's OpenAPI specification
- Verify the user's subscription tier includes access to the method
Invalid OpenAPI Specification
When resource creation fails due to specification errors:
- Validate the OpenAPI specification using an online validator
- Ensure all required fields (
openapi,info,paths) are present - Verify response schemas include
contentandschemadefinitions - Check that parameter types match OpenAPI 3.0 data types
- Confirm all
$refreferences resolve to defined components
See Also
- Scripts - Build serverless functions that invoke resources
- Templates - Bundle resources with pages and scripts
- Events - Trigger scripts with resource webhooks
- Authentication - API authentication and authorization
- Examples: Resources - Complete resource implementation examples