You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Similarly, to edit a tool's description, click the 3 dots and select **Edit description**. Use the dedicated modal to validate and save your updated description:
24
29
25
-

30
+
31
+
<videocontrols={false}aria-label="Editing a tool description"loop={true}autoPlay={true}muted={true}width="100%">
Copy file name to clipboardExpand all lines: docs/gram/examples/using-environments-with-vercel-ai-sdk.mdx
+73-2Lines changed: 73 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,27 @@ description: |
4
4
Learn how to use Gram environments with the Vercel AI SDK to manage authentication and configuration.
5
5
---
6
6
7
-
When initializing the Gram SDKs, specify which environment to use. The tools passed to the LLM will be bound to that environment.
7
+
[Environments](/docs/gram/concepts/environments) in Gram manage authentication credentials, API keys, and configuration variables for [toolsets](/docs/gram/concepts/toolsets). When building agent applications with the Vercel AI SDK or other AI frameworks, environments provide a secure way to manage the credentials needed to execute tools.
8
+
9
+
## Overview
10
+
11
+
Environments enable secure credential management without hardcoding sensitive information. They work by:
12
+
13
+
- Storing credentials and configuration in Gram's secure environment system
14
+
- Binding tools to a specific environment at initialization
15
+
- Executing all tool calls using the credentials from that environment
16
+
17
+
This approach is particularly useful for:
18
+
19
+
-**Multi-environment deployments**: Separate development, staging, and production credentials
20
+
-**Team collaboration**: Share toolsets without exposing credentials
21
+
-**Enterprise security**: Centralized credential management and rotation
22
+
23
+
Learn more about [environment concepts](/docs/gram/concepts/environments) and how to [configure environments](/docs/gram/gram-functions/configuring-environments).
24
+
25
+
## Using environments with Vercel AI SDK
26
+
27
+
The Vercel AI SDK integration demonstrates how to bind tools to a specific environment. The `environment` parameter in the `tools()` method determines which credentials the tools will use at runtime.
8
28
9
29
```ts filename="vercel-example.ts" {15}
10
30
import { generateText } from"ai";
@@ -34,6 +54,14 @@ const result = await generateText({
34
54
console.log(result.text);
35
55
```
36
56
57
+
In this example, all tools in the `marketing` toolset execute using credentials from the `production` environment. This keeps production API keys secure and separate from development credentials.
58
+
59
+
See the [Vercel AI SDK integration guide](/docs/gram/api-clients/using-vercel-ai-sdk-with-gram-mcp-servers) for complete setup instructions.
60
+
61
+
## Using environments with OpenAI Agents SDK
62
+
63
+
The OpenAI Agents SDK follows the same pattern, binding tools to an environment at initialization:
64
+
37
65
```py filename="openai-agents-example.py" {17}
38
66
import asyncio
39
67
import os
@@ -68,7 +96,19 @@ if __name__ == "__main__":
68
96
asyncio.run(main())
69
97
```
70
98
71
-
Environments are not required to use the Gram SDKs. You can pass the necessary variables directly when creating an instance. This is useful when users of your Gram toolsets prefer to use their own credentials.
99
+
The Python SDK provides the same environment binding capabilities, ensuring consistent credential management across different programming languages.
100
+
101
+
Learn more about [using the OpenAI Agents SDK with Gram](/docs/gram/api-clients/using-openai-agents-sdk-with-gram-mcp-servers).
102
+
103
+
## Bring your own environment variables
104
+
105
+
For applications where end users provide their own credentials, pass environment variables directly to the SDK adapter instead of referencing a managed environment. This is common when:
106
+
107
+
- Building multi-tenant applications where each user has their own API keys
108
+
- Creating developer tools where users supply their own credentials
109
+
- Distributing applications that integrate with user-owned services
@@ -82,6 +122,10 @@ const vercelAdapter = new VercelAdapter({
82
122
});
83
123
```
84
124
125
+
The `environmentVariables` object accepts any key-value pairs that the toolset's functions require. This approach bypasses Gram's environment system entirely, using credentials provided at runtime instead.
126
+
127
+
### Python example
128
+
85
129
```py filename="byo-env-vars.py" {6-9}
86
130
import os
87
131
from gram_ai.openai_agents import GramOpenAIAgents
@@ -94,3 +138,30 @@ gram = GramOpenAIAgents(
94
138
}
95
139
)
96
140
```
141
+
142
+
Both SDK adapters support the same `environment_variables` parameter, providing flexibility in how credentials are managed.
143
+
144
+
## Choosing between environments and direct variables
145
+
146
+
Consider these factors when deciding between managed environments and direct variables:
0 commit comments