Emergent

Building Your App › Integrations

API Usage on Emergent

This tutorial explains how to find and use API keys in three common situations: general APIs, OpenAI, and Stripe. API keys are secret strings that identify your application when it communicates with an external service. They are used for authentication, usage tracking, billing, and permission control.

Warning

Because API keys grant access to services and data, they must be handled securely.

What Is an API Key

An API key is a unique secret value issued by a service provider. When your app or agent makes a request, the key tells the provider who you are and what you are allowed to do.

Info

Most providers show the key only once, so it must be copied and stored securely at creation time.

Best Practices

Security Best Practices

  • Treat API keys like passwords
    • Never commit API keys to GitHub or source control
    • Never expose secret keys in frontend code
    • Store keys using environment variables
    • Rotate keys immediately if they are exposed

API Keys in General

API keys are typically found inside the developer or settings area of a service provider's dashboard.

Steps to Find and Generate an API Key

1

Create an account

Sign up for an account with the API provider.

2

Navigate to the API section

Look for sections labeled Developers, API Keys, Credentials, or Settings.

3

Generate a new key

Click Create or Generate API Key. If naming is supported, give the key a descriptive name.

4

Copy the key immediately

The key is usually shown only once. Store it securely as soon as it appears.


OpenAI API Keys

To use APIs from OpenAI, you must generate a secret API key from the OpenAI platform.

Steps to Find OpenAI API Keys

1

Log in to OpenAI

Sign in to the OpenAI platform using your account.

2

Open the API Keys page

Click your profile icon in the top right corner and select View API keys, or navigate to API Keys from the dashboard sidebar.

3

Create a new secret key

Click Create new secret key. Optionally name the key to indicate its purpose such as development or production.

4

Copy and store securely

Copy the key immediately. OpenAI keys usually start with sk- and must be kept secret.

Warning

Important Notes

  • OpenAI keys are secret keys only
  • They should be used in server-side code or secure agents
  • They must never be exposed in client-side applications

Stripe provides multiple API keys depending on environment and usage. These keys are managed in the Stripe dashboard.

Steps to Find Stripe API Keys

1

Log in to Stripe

Sign in to your Stripe account.

2

Open the Developers section

Click Developers in the left sidebar and select API keys.

3

Toggle Test mode or Live mode

Use the toggle in the top right corner to switch between environments. Each environment has its own keys.

4

Copy the appropriate keys

Make sure you are copying the correct key type for your use case.

Understanding Stripe Key Types

Publishable Key

Prefix: pk_

Safe for client-side use. Used to initialize Stripe in frontend applications.

Secret Key

Prefix: sk_

Must only be used on the server or in secure agents. Grants full access to Stripe resources.

Restricted Key

Prefix: rk_

Provides limited access to specific Stripe capabilities for improved security.

Warning

Security Notes

  • Never expose Stripe secret keys in frontend code
  • Always verify whether you are using test or live keys
  • Rotate keys immediately if they are leaked

How to Use API Keys in Emergent

After generating your API keys, you will connect them to your Emergent project by sharing them with the agent and confirming they are stored correctly in environment variables.

1

Share the key with the agent

During project setup or configuration, provide the API key when the agent prompts for it.

2

Verify the key is stored in `.env`

Open the Emergent environment variables and confirm the key appears in the .env configuration.

3

Check variable names

Ensure the environment variable name exactly matches what the agent or integration expects.

4

Confirm runtime availability

Make sure the environment variables are accessible at runtime before running or deploying the project.

Troubleshooting

  • Confirm the correct API key exists in the .env variables
  • Verify you are using the correct environment such as test or live
  • Check for typos or missing characters in the key
  • Restart or redeploy the project to reload environment variables
  • Verify the variable names match exactly what the integration expects
  • Check that the .env file is in the correct directory

Success

Once the key is present in the Emergent environment variables and visible to the agent, the integration should work as expected.

Made with Emergent