Automation shouldn’t sign in as a person. Streamtime has two kinds of machine credential:
API key
OAuth client
For
Scripts, CI, Terraform, MCP clients and the CLI
Applications that sign in with OAuth client credentials, for example a Kafka producer
Scope
One organization, one role
One organization, optionally limited to some Kafka clusters
Available
Always
With Streamtime identity as the sign-in
Sent as
X-Streamtime-Key header
A token from the OAuth token endpoint
The key or secret is shown once, when it is created or rotated. Store it in your secret manager straight away.
API key roles
Give each key the least it needs. A key has one of these roles: Agent (the least privileged), MCP Agent (required to connect an MCP client), Cluster Administrator, Infrastructure Administrator, Billing Administrator or Administrator (everything in the organization). The roles are the same ones people have; see User Management.
packagemainimport("bytes""crypto/rand""encoding/hex""encoding/json""net/http""os")constapi="https://api.example.com/organizations/<org>"// newKey returns a random idempotency key.funcnewKey()string{b:=make([]byte,16)rand.Read(b)returnhex.EncodeToString(b)}// call sends one request with the access token and a JSON body (or none).// An optional idempotency key is sent as the Idempotency-Key header.funccall(method,pathstring,bodyany,idempotencyKey...string)(*http.Response,error){varbufbytes.Bufferifbody!=nil{iferr:=json.NewEncoder(&buf).Encode(body);err!=nil{returnnil,err}}req,err:=http.NewRequest(method,api+path,&buf)iferr!=nil{returnnil,err}req.Header.Set("Authorization","Bearer "+os.Getenv("STREAMTIME_TOKEN"))req.Header.Set("Content-Type","application/json")iflen(idempotencyKey)>0{req.Header.Set("Idempotency-Key",idempotencyKey[0])}returnhttp.DefaultClient.Do(req)}
Create an API key
Open the API Keys page from the account menu (organization administrators).
Select Create API Key, enter a Name and choose the Role.
The response’s key is the only time the key is returned. List keys with GET $API/api-keys/; revoke one with DELETE $API/api-keys/<id>/.
fromstreamtime_sdk.api.api_keysimportorganizations_api_keys_createfromstreamtime_sdk.modelsimportAPIKEYcreated=organizations_api_keys_create.sync(ORG,client=client,body=APIKEY.from_dict({"name":"ci","role":"Cluster Administrator"}))print(created.key)# shown once
import{organizationsApiKeysCreate}from"./client";const{data}=awaitorganizationsApiKeysCreate({path:{org_identifier:org},body:{name:"ci",role:"Cluster Administrator"},});console.log(data?.key);// shown once
The key value is sensitive and kept in Terraform state after creation; an import can’t recover it, so protect the state storage. Destroying the resource revokes the key.
Its access settings can’t be changed in place, so a change replaces the client. The secret is sensitive and kept in Terraform state; destroying the resource revokes the client.