Availability
The Service API is available to plugins in AI Studio and on Edge Gateways.
The Service API lets plugins read and change platform data, such as LLMs, Apps and plugin KV storage. Plugins call it through the
Context.Services interface of the unified plugin SDK (pkg/plugin_sdk).
Services by Runtime
The services that a plugin can use depend on its runtime:- Universal services, in AI Studio and on Edge Gateways: KV storage, the logger, and the Event Service.
- Studio Services, in AI Studio: LLMs, tools, plugins, Apps, notifications, resource types, permissions, governed metadata, governance reads and schedules. Refer to Studio Services.
- RAG and datasource services, in AI Studio: embeddings, document storage, vector search and datasource management. Refer to RAG and Datasource Services.
- Gateway Services, on Edge Gateways: Apps, LLMs, budget status, model prices, credential validation and App storage. Refer to Gateway Services.
Access Pattern
All services are accessed through theContext.Services interface provided to your plugin handlers:
Expandable
Initialization and Connection Warmup
For Service API access in AI Studio, plugins use a session-based broker pattern. The SDK does most of the setup. For reliable Service API access, warm up the connection as this section shows.The Connection Warmup Pattern
Critical: The go-plugin broker only accepts ONE connection per broker ID. A plugin can use both the Event Service and the Management Service API. Then the service that dials first succeeds, and the two services share the connection. To ensure reliable Service API access, implementSessionAware and warm up the connection in OnSessionReady:
Expandable
Why Warmup Is Required
Without the warmup pattern, a plugin that uses the Service API during an RPC call can get “timeout waiting for connection info” errors. The causes are:- The broker connection is time-sensitive. Open it early.
- A late dial, during an RPC call from the UI, can fail.
- Event subscriptions and Service API calls share the same connection. One warmup opens the connection for both.
Legacy Pattern (Still Supported)
The older pattern of extracting the broker ID manually duringInitialize still works but is not recommended:
Expandable
OpenSession. You only need to implement SessionAware and warm up the connection.
Universal Services
These services are available in both Studio and Gateway runtimes.KV Storage
Key-value storage for plugin data:- Studio: PostgreSQL-backed, shared across hosts, durable
- Gateway: Local database, per-instance, ephemeral
kv.readwrite scope.
Write Data
true if the call created the key, and false if it updated the key. Pass an expiry time (*time.Time) as the last argument, or nil for no expiry.
Example:
Write Data with TTL
Read Data
Delete Data
true if the key existed.
List Keys
ctx.Services.KV().List(ctx, prefix) is not implemented. In both runtimes, it returns the error list operation not yet supported.
Direct SDK Calls
Studio plugins can also call the KV functions of theai_studio_sdk package: WritePluginKV, WritePluginKVWithTTL, ReadPluginKV and DeletePluginKV. They take the same arguments as the KV() methods.
Logger
Structured logging with key-value pairs:Expandable
Scopes
Each Service API call in AI Studio needs a scope. Declare the scopes underpermissions.services in the plugin manifest. Refer to Plugin Scopes.
Error Handling
Service API calls return standard Go errors:- Permission denied: Missing required scope
- Not found: Resource doesn’t exist
- Invalid argument: Bad request parameters
- Unavailable: Service not ready
Expandable
Context and Timeouts
Always use contexts with timeouts:Valid UTF-8 in Protobuf Strings
Protobuf string fields must contain valid UTF-8. The SDK cleans strings at its own gRPC boundary, for example inCall() and PortalCall(). If your plugin puts external data (file content, third-party responses) into a protobuf string field, clean the data first. Otherwise the call fails with string field contains invalid UTF-8.
Best Practices
-
Check SDK Initialization:
-
Check the Runtime: Check
ctx.Runtimebefore you call a runtime-specific service. -
Type Assert the Results: Gateway Services and some Studio Services return
interface{}. Type assert the result to the correct response type. -
Handle Pagination:
Expandable
-
Cache Results: Cache data that you read often, in memory or in KV storage, to reduce API calls.
-
Log Errors: Use
ctx.Services.Logger()for consistent structured logs, and check the error of every Service API call.
Complete Examples
For complete working examples of Service API usage:- Studio:
examples/plugins/studio/service-api-test/- Comprehensive Studio Services testing - Gateway:
examples/plugins/gateway/gateway-service-test/- Gateway Services examples - Rate Limiter:
examples/plugins/studio/llm-rate-limiter-multiphase/- Multi-capability plugin with KV storage - Scheduler:
examples/plugins/studio/scheduler-demo/- Scheduled tasks with manifest and API patterns