Skip to content

Conversation

@jianshen92
Copy link
Contributor

@jianshen92 jianshen92 commented Dec 10, 2025

What does this PR address?

As requested by customer

Python

Programmatic Usage (Python SDK)

  import bentoml
  from datetime import datetime, timedelta

  # Initialize the client
  client = bentoml.BentoCloudClient(api_key="your_api_key")

  # List all tokens
  tokens = client.api_token.list(search="my-token")
  for token in tokens:
      print(f"{token.name}: {token.uid}")

  # Create a new token
  new_token = client.api_token.create(
      name="my-api-token",
      description="Token for CI/CD pipeline",
      scopes=["api", "read_cluster"],
      expired_at=datetime.now() + timedelta(days=30)
  )
  print(f"Token value (save this!): {new_token.token}")

  # Get token details
  token = client.api_token.get(token_uid="token_abc123")
  print(f"Scopes: {token.scopes}")
  print(f"Expires: {token.expired_at}")

  # Delete a token
  client.api_token.delete(token_uid="token_abc123")

CLI

List all API tokens

  bentoml api-token list
  bentoml api-token list --output json

Get a specific token by UID

  bentoml api-token get <token-uid>
  bentoml api-token get <token-uid> --output json

Create a new token

  bentoml api-token create my-token --scope api --scope read_cluster
  bentoml api-token create my-token -s api -s write_organization --expires 30d

Delete a token

  bentoml api-token delete <token-uid>

Fixes #(issue)

Before submitting:

@jianshen92 jianshen92 marked this pull request as ready for review December 10, 2025 17:13
@jianshen92 jianshen92 requested a review from a team as a code owner December 10, 2025 17:13
@jianshen92 jianshen92 requested review from frostming and ssheng and removed request for a team December 10, 2025 17:13
@jianshen92 jianshen92 changed the title Api token sdk feat: API token sdk Dec 10, 2025
Copy link
Collaborator

@frostming frostming left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also expose bentoml.api_token module like bentoml.deployment and others?

@jianshen92
Copy link
Contributor Author

Should we also expose bentoml.api_token module like bentoml.deployment and others?

sounds good. just made a push

@jianshen92 jianshen92 merged commit 6a41598 into bentoml:main Dec 11, 2025
47 of 49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants