PgBeam Docs
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

ParameterTypeRequiredDescription
ctxcontext.ContextYesRequest context
projectIDstringYesUnique project identifier (prefixed, e.g. prj_xxx).
reqpgbeam.CreateAgentCredentialRequestYesRequest body
req.NamestringYesHuman-readable label for the credential.
req.PolicyProfileIDstringYesThe policy profile to enforce for this credential.
req.PrincipalType*stringNoWhether this credential represents an autonomous agent or a human operator.
req.ExpiresAt*stringNoOptional 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

StatusDescription
400Invalid request parameters.
401Missing or invalid authentication.
403Agent credential quota reached for the organization plan.
404Resource not found.
409Resource already exists or conflicts with current state.
429Rate limited. Try again later.

On this page