Skip to content

Commit 03eca92

Browse files
docs: simplify examples to cURL only
Remove TypeScript and Python code examples, keeping only cURL for cleaner documentation. VAP-11219 Co-Authored-By: Claude <noreply@anthropic.com>
1 parent a71c951 commit 03eca92

1 file changed

Lines changed: 5 additions & 181 deletions

File tree

fern/chat/variable-substitution.mdx

Lines changed: 5 additions & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ When you create a session with `assistantOverrides.variableValues`, the system:
2727
3. Stores the **pre-substituted assistant** in the session
2828
4. Saves the original variable values in `session.metadata.variableValues` for reference
2929

30-
<CodeBlocks>
31-
```bash title="cURL"
30+
```bash title="Create session with variables"
3231
curl -X POST https://api.vapi.ai/session \
3332
-H "Authorization: Bearer $VAPI_API_KEY" \
3433
-H "Content-Type: application/json" \
@@ -42,29 +41,6 @@ curl -X POST https://api.vapi.ai/session \
4241
}
4342
}'
4443
```
45-
```typescript title="TypeScript"
46-
const session = await vapi.sessions.create({
47-
assistantId: "your-assistant-id",
48-
assistantOverrides: {
49-
variableValues: {
50-
name: "John",
51-
company: "Acme Corp"
52-
}
53-
}
54-
});
55-
```
56-
```python title="Python"
57-
session = vapi.sessions.create(
58-
assistant_id="your-assistant-id",
59-
assistant_overrides={
60-
"variableValues": {
61-
"name": "John",
62-
"company": "Acme Corp"
63-
}
64-
}
65-
)
66-
```
67-
</CodeBlocks>
6844

6945
If your assistant's system prompt was `"You are a helpful assistant for {{name}} at {{company}}"`, the session stores: `"You are a helpful assistant for John at Acme Corp"`.
7046

@@ -84,9 +60,7 @@ When you send a chat request with a `sessionId`:
8460

8561
Once you set variables at session creation, they persist for all chats in that session:
8662

87-
<CodeBlocks>
88-
```bash title="cURL"
89-
# Chat using the session - variables already applied
63+
```bash title="Chat using the session"
9064
curl -X POST https://api.vapi.ai/chat \
9165
-H "Authorization: Bearer $VAPI_API_KEY" \
9266
-H "Content-Type: application/json" \
@@ -95,21 +69,6 @@ curl -X POST https://api.vapi.ai/chat \
9569
"input": "What is my name and company?"
9670
}'
9771
```
98-
```typescript title="TypeScript"
99-
const chat = await vapi.chat.create({
100-
sessionId: "session_xyz789",
101-
input: "What is my name and company?"
102-
});
103-
// Response will reference "John" and "Acme Corp"
104-
```
105-
```python title="Python"
106-
chat = vapi.chat.create(
107-
session_id="session_xyz789",
108-
input="What is my name and company?"
109-
)
110-
# Response will reference "John" and "Acme Corp"
111-
```
112-
</CodeBlocks>
11372

11473
The assistant will respond with the values set at session creation (John, Acme Corp).
11574

@@ -119,9 +78,7 @@ The assistant will respond with the values set at session creation (John, Acme C
11978
Passing new `variableValues` in a chat request **will not** change the session's pre-substituted assistant. The template placeholders no longer exist.
12079
</Warning>
12180

122-
<CodeBlocks>
123-
```bash title="cURL"
124-
# This will NOT change the assistant's context
81+
```bash title="This will NOT change the assistant's context"
12582
curl -X POST https://api.vapi.ai/chat \
12683
-H "Authorization: Bearer $VAPI_API_KEY" \
12784
-H "Content-Type: application/json" \
@@ -136,44 +93,14 @@ curl -X POST https://api.vapi.ai/chat \
13693
}
13794
}'
13895
```
139-
```typescript title="TypeScript"
140-
// This will NOT change the assistant's context
141-
const chat = await vapi.chat.create({
142-
sessionId: "session_xyz789",
143-
input: "What is my name and company?",
144-
assistantOverrides: {
145-
variableValues: {
146-
name: "Jane",
147-
company: "Wayne Enterprises"
148-
}
149-
}
150-
});
151-
// Response will STILL reference "John" and "Acme Corp"
152-
```
153-
```python title="Python"
154-
# This will NOT change the assistant's context
155-
chat = vapi.chat.create(
156-
session_id="session_xyz789",
157-
input="What is my name and company?",
158-
assistant_overrides={
159-
"variableValues": {
160-
"name": "Jane",
161-
"company": "Wayne Enterprises"
162-
}
163-
}
164-
)
165-
# Response will STILL reference "John" and "Acme Corp"
166-
```
167-
</CodeBlocks>
16896

16997
The assistant still responds with "John" and "Acme Corp" because the original templates were already replaced.
17098

17199
### Provide fresh templates to use new values
172100

173101
To use different variable values mid-session, provide a new template with `{{ }}` placeholders along with the new values:
174102

175-
<CodeBlocks>
176-
```bash title="cURL"
103+
```bash title="Override with fresh template"
177104
curl -X POST https://api.vapi.ai/chat \
178105
-H "Authorization: Bearer $VAPI_API_KEY" \
179106
-H "Content-Type: application/json" \
@@ -193,43 +120,6 @@ curl -X POST https://api.vapi.ai/chat \
193120
}
194121
}'
195122
```
196-
```typescript title="TypeScript"
197-
const chat = await vapi.chat.create({
198-
sessionId: "session_xyz789",
199-
input: "What is my name and company?",
200-
assistantOverrides: {
201-
model: {
202-
provider: "openai",
203-
model: "gpt-4.1",
204-
systemPrompt: "You are a helpful assistant for {{name}} at {{company}}. Be very formal."
205-
},
206-
variableValues: {
207-
name: "Jane",
208-
company: "Wayne Enterprises"
209-
}
210-
}
211-
});
212-
// Response will now reference "Jane" and "Wayne Enterprises"
213-
```
214-
```python title="Python"
215-
chat = vapi.chat.create(
216-
session_id="session_xyz789",
217-
input="What is my name and company?",
218-
assistant_overrides={
219-
"model": {
220-
"provider": "openai",
221-
"model": "gpt-4.1",
222-
"systemPrompt": "You are a helpful assistant for {{name}} at {{company}}. Be very formal."
223-
},
224-
"variableValues": {
225-
"name": "Jane",
226-
"company": "Wayne Enterprises"
227-
}
228-
}
229-
)
230-
# Response will now reference "Jane" and "Wayne Enterprises"
231-
```
232-
</CodeBlocks>
233123

234124
Now the assistant responds with "Jane" and "Wayne Enterprises" because fresh template placeholders were provided.
235125

@@ -250,24 +140,7 @@ Now the assistant responds with "Jane" and "Wayne Enterprises" because fresh tem
250140

251141
### For consistent variables across a session
252142

253-
Pass `assistantOverrides.variableValues` once when creating the session. Subsequent chat requests only need the `sessionId` and `input`:
254-
255-
```typescript title="Recommended pattern"
256-
// 1. Create session with variables
257-
const session = await vapi.sessions.create({
258-
assistantId: "your-assistant-id",
259-
assistantOverrides: {
260-
variableValues: {
261-
customerName: "Sarah",
262-
accountType: "Premium"
263-
}
264-
}
265-
});
266-
267-
// 2. All chats use the session - variables persist
268-
await vapi.chat.create({ sessionId: session.id, input: "Hello!" });
269-
await vapi.chat.create({ sessionId: session.id, input: "What's my account type?" });
270-
```
143+
Pass `assistantOverrides.variableValues` once when creating the session. Subsequent chat requests only need the `sessionId` and `input`.
271144

272145
### For different variables per conversation
273146

@@ -276,61 +149,12 @@ Choose one of these approaches:
276149
<AccordionGroup>
277150
<Accordion title="Option A: Don't use sessions">
278151
Pass the full assistant configuration in each chat request. This gives you complete control over variables per request.
279-
280-
```typescript
281-
const chat = await vapi.chat.create({
282-
assistantId: "your-assistant-id",
283-
assistantOverrides: {
284-
variableValues: {
285-
customerName: "Different Customer",
286-
accountType: "Basic"
287-
}
288-
},
289-
input: "Hello!"
290-
});
291-
```
292152
</Accordion>
293153
<Accordion title="Option B: Override with fresh templates">
294154
Include a new system prompt (or other text field) with `{{ }}` placeholders plus new `variableValues` in your chat request.
295-
296-
```typescript
297-
const chat = await vapi.chat.create({
298-
sessionId: "existing-session-id",
299-
assistantOverrides: {
300-
model: {
301-
provider: "openai",
302-
model: "gpt-4.1",
303-
systemPrompt: "You assist {{customerName}} with their {{accountType}} account."
304-
},
305-
variableValues: {
306-
customerName: "New Customer",
307-
accountType: "Enterprise"
308-
}
309-
},
310-
input: "Hello!"
311-
});
312-
```
313155
</Accordion>
314156
<Accordion title="Option C: Create separate sessions">
315157
Create a new session for each unique variable context. This keeps conversations cleanly separated.
316-
317-
```typescript
318-
// Session for Customer A
319-
const sessionA = await vapi.sessions.create({
320-
assistantId: "your-assistant-id",
321-
assistantOverrides: {
322-
variableValues: { customerName: "Customer A" }
323-
}
324-
});
325-
326-
// Session for Customer B
327-
const sessionB = await vapi.sessions.create({
328-
assistantId: "your-assistant-id",
329-
assistantOverrides: {
330-
variableValues: { customerName: "Customer B" }
331-
}
332-
});
333-
```
334158
</Accordion>
335159
</AccordionGroup>
336160

0 commit comments

Comments
 (0)