Agents
CreateAgentCredential
Create an agent credential
Issues a scoped Postgres login and hosted MCP token for an AI agent. The connection string and MCP token are returned once and cannot be retrieved again.
Usage
result, err := client.Agents.CreateAgentCredential(ctx, "prj_xxx", pgbeam.CreateAgentCredentialRequest{
Name: "...",
PolicyProfileID: "...",
})Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| ctx | context.Context | Yes | Request context |
| projectID | string | Yes | Unique project identifier (prefixed, e.g. prj_xxx). |
| req | pgbeam.CreateAgentCredentialRequest | Yes | Request body |
| req.Name | string | Yes | Human-readable label for the credential. |
| req.PolicyProfileID | string | Yes | The policy profile to enforce for this credential. |
| req.PrincipalType | *string | No | Whether this credential represents an autonomous agent or a human operator. |
| req.ExpiresAt | *string | No | Optional expiry. When set, the credential becomes unusable at this time (must be in the future). Omit or set null for a credential that never expires. |
Response
(*pgbeam.AgentCredentialSecrets, error) — agent credential created. secrets shown once.
Example
import pgbeam "go.pgbeam.com/sdk"
client := pgbeam.NewClient(&pgbeam.ClientOptions{
APIKey: "pgb_your_api_key",
})
result, err := client.Agents.CreateAgentCredential(ctx, "prj_xxx", pgbeam.CreateAgentCredentialRequest{
Name: "...",
PolicyProfileID: "...",
PrincipalType: "agent",
ExpiresAt: "...",
})
if err != nil {
log.Fatal(err)
}
fmt.Println(result)Errors
| Status | Description |
|---|---|
| 400 | Invalid request parameters. |
| 401 | Missing or invalid authentication. |
| 403 | Agent credential quota reached for the organization plan. |
| 404 | Resource not found. |
| 409 | Resource already exists or conflicts with current state. |
| 429 | Rate limited. Try again later. |