> ## Documentation Index
> Fetch the complete documentation index at: https://novita.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Get a Secret

`Novita.secret``.get()` fetches the metadata of an active Secret by name. It returns `SecretBinding` metadata and does not return the real value. Use it to confirm a Secret exists and inspect its host allow list before referencing it from a sandbox.

## Prerequisites

```bash CLI icon="terminal" theme={"system"}
export OPENAI_API_KEY="your-openai-api-key"
```

## Example

The example ensures a Secret exists, fetches its metadata with `novita.secret.get()`, launches a sandbox that references it, uses the placeholder from inside the sandbox, and kills the sandbox when done.

<CodeGroup>
  ```python Python icon="python" theme={"system"}
  import os
  import uuid

  from novita_sandbox import Novita

  secret_name = f"openai-example-{uuid.uuid4().hex[:12]}"
  openai_api_key = os.environ["OPENAI_API_KEY"]
  novita = Novita()

  # Ensure the Secret exists (created once, reused afterwards).
  novita.secret.create(
      name=secret_name,
      value=openai_api_key,
      hosts=["api.openai.com"],
      description="Sandbox Secrets example",
  )

  # Handle secret: fetch the Secret metadata by name (no real value returned).
  fetched = novita.secret.get(secret_name)
  print(fetched)

  # Create sandbox: reference the fetched Secret by name.
  sandbox = novita.sandbox.create(
      secret_envs={"OPENAI_API_KEY": secret_name},
  )

  try:
      # Use the secret: the proxy substitutes the real value for the allow-listed host.
      result = sandbox.commands.run(
          'curl -s https://api.openai.com/v1/models '
          '-H "Authorization: Bearer $OPENAI_API_KEY"'
      )
      print(result.stdout)
  finally:
      # Kill sandbox when done.
      sandbox.kill()
  ```

  ```js JavaScript & TypeScript icon="js" theme={"system"}
  import 'dotenv/config'
  import { randomUUID } from 'crypto'
  import { Novita } from 'novita-sandbox'

  const secretName = `openai-example-${randomUUID().slice(0, 12)}`
  const openaiApiKey = process.env.OPENAI_API_KEY
  const novita = new Novita()

  // Ensure the Secret exists (created once, reused afterwards).
  await novita.secret.create({
    name: secretName,
    value: openaiApiKey,
    hosts: ['api.openai.com'],
    description: 'Sandbox Secrets example',
  })

  // Handle secret: fetch the Secret metadata by name (no real value returned).
  const fetched = await novita.secret.get(secretName)
  console.log(fetched)

  // Create sandbox: reference the fetched Secret by name.
  const sandbox = await novita.sandbox.create({
    secretEnvs: { OPENAI_API_KEY: secretName },
  })

  try {
    const result = await sandbox.commands.run(
      'curl -s https://api.openai.com/v1/models -H "Authorization: Bearer $OPENAI_API_KEY"'
    )
    console.log(result.stdout)
  } finally {
    await sandbox.kill()
  }
  ```
</CodeGroup>

<Note>
  `novita.secret.get()` returns `SecretBinding` metadata only — it never returns the real value. If the name does not exist or has been deleted, the call returns `404 Not Found`.
</Note>
