fix: add Authorization header to agent API docs examples
This commit is contained in:
parent
95cb0a96f0
commit
bf97513a59
1 changed files with 25 additions and 10 deletions
|
|
@ -120,13 +120,17 @@ function ApiDocsSection({ agent, agentTools }: { agent: Agent; agentTools: Agent
|
||||||
language: 'bash',
|
language: 'bash',
|
||||||
code: `curl -X POST '${endpoint}' \\
|
code: `curl -X POST '${endpoint}' \\
|
||||||
-H 'Content-Type: application/json' \\
|
-H 'Content-Type: application/json' \\
|
||||||
|
-H 'Authorization: Bearer YOUR_TPMJS_API_KEY' \\
|
||||||
-d '{ "message": "Hello, what can you help me with?" }'`,
|
-d '{ "message": "Hello, what can you help me with?" }'`,
|
||||||
},
|
},
|
||||||
typescript: {
|
typescript: {
|
||||||
language: 'typescript',
|
language: 'typescript',
|
||||||
code: `const response = await fetch('${endpoint}', {
|
code: `const response = await fetch('${endpoint}', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': 'Bearer YOUR_TPMJS_API_KEY'
|
||||||
|
},
|
||||||
body: JSON.stringify({ message: 'Hello, what can you help me with?' })
|
body: JSON.stringify({ message: 'Hello, what can you help me with?' })
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -144,6 +148,7 @@ while (true) {
|
||||||
code: `import requests
|
code: `import requests
|
||||||
|
|
||||||
response = requests.post('${endpoint}',
|
response = requests.post('${endpoint}',
|
||||||
|
headers={'Authorization': 'Bearer YOUR_TPMJS_API_KEY'},
|
||||||
json={'message': 'Hello, what can you help me with?'},
|
json={'message': 'Hello, what can you help me with?'},
|
||||||
stream=True)
|
stream=True)
|
||||||
|
|
||||||
|
|
@ -158,7 +163,10 @@ import { createAnthropic } from '@ai-sdk/anthropic';
|
||||||
// Option 1: Use hosted agent via fetch
|
// Option 1: Use hosted agent via fetch
|
||||||
const response = await fetch('${endpoint}', {
|
const response = await fetch('${endpoint}', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': 'Bearer YOUR_TPMJS_API_KEY'
|
||||||
|
},
|
||||||
body: JSON.stringify({ message: 'Hello!' })
|
body: JSON.stringify({ message: 'Hello!' })
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -176,23 +184,28 @@ const { textStream } = streamText({
|
||||||
curl: {
|
curl: {
|
||||||
language: 'bash',
|
language: 'bash',
|
||||||
code: `# List conversations
|
code: `# List conversations
|
||||||
curl '${listEndpoint}?limit=20&offset=0'
|
curl -H 'Authorization: Bearer YOUR_TPMJS_API_KEY' \\
|
||||||
|
'${listEndpoint}?limit=20&offset=0'
|
||||||
|
|
||||||
# Get conversation with messages
|
# Get conversation with messages
|
||||||
curl '${endpoint}?limit=50&offset=0'
|
curl -H 'Authorization: Bearer YOUR_TPMJS_API_KEY' \\
|
||||||
|
'${endpoint}?limit=50&offset=0'
|
||||||
|
|
||||||
# Delete conversation
|
# Delete conversation
|
||||||
curl -X DELETE '${endpoint}'`,
|
curl -X DELETE -H 'Authorization: Bearer YOUR_TPMJS_API_KEY' \\
|
||||||
|
'${endpoint}'`,
|
||||||
},
|
},
|
||||||
typescript: {
|
typescript: {
|
||||||
language: 'typescript',
|
language: 'typescript',
|
||||||
code: `// List conversations
|
code: `const headers = { 'Authorization': 'Bearer YOUR_TPMJS_API_KEY' };
|
||||||
const list = await fetch('${listEndpoint}?limit=20&offset=0');
|
|
||||||
|
// List conversations
|
||||||
|
const list = await fetch('${listEndpoint}?limit=20&offset=0', { headers });
|
||||||
const { data, pagination } = await list.json();
|
const { data, pagination } = await list.json();
|
||||||
// data: [{ id, slug, title, messageCount }], pagination: { hasMore }
|
// data: [{ id, slug, title, messageCount }], pagination: { hasMore }
|
||||||
|
|
||||||
// Get conversation with messages
|
// Get conversation with messages
|
||||||
const conv = await fetch('${endpoint}?limit=50&offset=0');
|
const conv = await fetch('${endpoint}?limit=50&offset=0', { headers });
|
||||||
const { data: conversation } = await conv.json();
|
const { data: conversation } = await conv.json();
|
||||||
// conversation: { id, slug, title, messages: [...] }`,
|
// conversation: { id, slug, title, messages: [...] }`,
|
||||||
},
|
},
|
||||||
|
|
@ -200,12 +213,14 @@ const { data: conversation } = await conv.json();
|
||||||
language: 'python',
|
language: 'python',
|
||||||
code: `import requests
|
code: `import requests
|
||||||
|
|
||||||
|
headers = {'Authorization': 'Bearer YOUR_TPMJS_API_KEY'}
|
||||||
|
|
||||||
# List conversations
|
# List conversations
|
||||||
resp = requests.get('${listEndpoint}', params={'limit': 20, 'offset': 0})
|
resp = requests.get('${listEndpoint}', headers=headers, params={'limit': 20, 'offset': 0})
|
||||||
data = resp.json() # data['data'], data['pagination']['hasMore']
|
data = resp.json() # data['data'], data['pagination']['hasMore']
|
||||||
|
|
||||||
# Get conversation with messages
|
# Get conversation with messages
|
||||||
resp = requests.get('${endpoint}', params={'limit': 50, 'offset': 0})
|
resp = requests.get('${endpoint}', headers=headers, params={'limit': 50, 'offset': 0})
|
||||||
conv = resp.json() # conv['data']['messages']`,
|
conv = resp.json() # conv['data']['messages']`,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue