Skip to content

Commit a50562b

Browse files
authored
Anthropic Web Search (#4906)
1 parent 525e140 commit a50562b

File tree

52 files changed

+2124
-804
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2124
-804
lines changed

bifrost/lib/clients/jawnTypes/private.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,6 +1602,13 @@ Json: JsonObject;
16021602
ending_event_id?: string;
16031603
trigger_event_id?: string;
16041604
start_timestamp?: string;
1605+
annotations?: {
1606+
content?: string;
1607+
title: string;
1608+
url: string;
1609+
/** @enum {string} */
1610+
type: "url_citation";
1611+
}[];
16051612
reasoning?: string;
16061613
deleted?: boolean;
16071614
contentArray?: components["schemas"]["Message"][];

bifrost/lib/clients/jawnTypes/public.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,6 +1588,13 @@ export interface components {
15881588
ending_event_id?: string;
15891589
trigger_event_id?: string;
15901590
start_timestamp?: string;
1591+
annotations?: {
1592+
content?: string;
1593+
title: string;
1594+
url: string;
1595+
/** @enum {string} */
1596+
type: "url_citation";
1597+
}[];
15911598
reasoning?: string;
15921599
deleted?: boolean;
15931600
contentArray?: components["schemas"]["Message"][];
@@ -2960,6 +2967,8 @@ Json: JsonObject;
29602967
AuthorName: "anthropic" | "openai" | "perplexity" | "deepseek" | "cohere" | "xai" | "google" | "meta-llama" | "mistralai" | "amazon" | "microsoft" | "nvidia" | "qwen" | "moonshotai" | "alibaba" | "passthrough";
29612968
/** @enum {string} */
29622969
StandardParameter: "max_tokens" | "max_completion_tokens" | "temperature" | "top_p" | "top_k" | "stop" | "stream" | "frequency_penalty" | "presence_penalty" | "repetition_penalty" | "seed" | "tools" | "tool_choice" | "functions" | "function_call" | "reasoning" | "include_reasoning" | "thinking" | "response_format" | "json_mode" | "truncate" | "min_p" | "logit_bias" | "logprobs" | "top_logprobs" | "structured_outputs" | "verbosity";
2970+
/** @enum {string} */
2971+
PluginId: "web";
29632972
RateLimits: {
29642973
/** Format: double */
29652974
rpm?: number;
@@ -3040,6 +3049,7 @@ Json: JsonObject;
30403049
provider: components["schemas"]["ModelProviderName"];
30413050
author: components["schemas"]["AuthorName"];
30423051
supportedParameters: components["schemas"]["StandardParameter"][];
3052+
supportedPlugins?: components["schemas"]["PluginId"][];
30433053
rateLimits?: components["schemas"]["RateLimits"];
30443054
endpointConfigs: components["schemas"]["Record_string.EndpointConfig_"];
30453055
crossRegion?: boolean;

docs/docs.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"pages": [
2828
"gateway/overview",
2929
"gateway/provider-routing",
30+
3031
{
3132
"group": "Features",
3233
"pages": [
@@ -40,7 +41,10 @@
4041
},
4142
{
4243
"group": "Concepts",
43-
"pages": ["gateway/concepts/prompt-caching"]
44+
"pages": [
45+
"gateway/concepts/prompt-caching",
46+
"gateway/web-search"
47+
]
4448
}
4549
]
4650
},

docs/gateway/web-search.mdx

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
---
2+
title: "Web Search with Helicone Gateway"
3+
description: "Enable web search capabilities for Anthropic models through Helicone's Gateway using the :online suffix"
4+
---
5+
6+
# Web Search Overview
7+
8+
Helicone Gateway supports web search for Anthropic models, allowing Claude to search the internet and provide up-to-date information with citations. This feature is enabled by appending `:online` to the model name, following the same pattern as OpenRouter.
9+
10+
## How it Works
11+
12+
When you append `:online` to an Anthropic model name (e.g., `claude-3-5-sonnet-20241022:online`), Helicone automatically:
13+
14+
1. Enables the web search tool for the request
15+
2. Routes the request to Anthropic with the appropriate web search configuration
16+
3. Returns the response with citations formatted as annotations
17+
18+
## Quick Start
19+
20+
<Tabs>
21+
<Tab title="Python">
22+
```python
23+
import openai
24+
25+
client = openai.OpenAI(
26+
api_key="YOUR_ANTHROPIC_API_KEY",
27+
base_url="https://gateway.helicone.ai/v1",
28+
default_headers={
29+
"Helicone-Auth": "Bearer YOUR_HELICONE_API_KEY",
30+
"Helicone-Target-Url": "https://api.anthropic.com",
31+
}
32+
)
33+
34+
response = client.chat.completions.create(
35+
model="claude-3-5-sonnet-20241022:online", # Note the :online suffix
36+
messages=[
37+
{"role": "user", "content": "What are the latest developments in AI?"}
38+
]
39+
)
40+
41+
# Access citations if available
42+
if response.choices[0].message.annotations:
43+
for annotation in response.choices[0].message.annotations:
44+
print(f"Source: {annotation['url_citation']['title']}")
45+
print(f"URL: {annotation['url_citation']['url']}")
46+
```
47+
</Tab>
48+
49+
<Tab title="Node.js">
50+
```javascript
51+
import OpenAI from 'openai';
52+
53+
const openai = new OpenAI({
54+
apiKey: 'YOUR_ANTHROPIC_API_KEY',
55+
baseURL: 'https://gateway.helicone.ai/v1',
56+
defaultHeaders: {
57+
'Helicone-Auth': 'Bearer YOUR_HELICONE_API_KEY',
58+
'Helicone-Target-Url': 'https://api.anthropic.com',
59+
}
60+
});
61+
62+
const response = await openai.chat.completions.create({
63+
model: 'claude-3-5-sonnet-20241022:online', // Note the :online suffix
64+
messages: [
65+
{ role: 'user', content: 'What are the latest developments in AI?' }
66+
]
67+
});
68+
69+
// Access citations if available
70+
if (response.choices[0].message.annotations) {
71+
response.choices[0].message.annotations.forEach(annotation => {
72+
console.log(`Source: ${annotation.url_citation.title}`);
73+
console.log(`URL: ${annotation.url_citation.url}`);
74+
});
75+
}
76+
```
77+
</Tab>
78+
79+
<Tab title="cURL">
80+
```bash
81+
curl https://gateway.helicone.ai/v1/chat/completions \
82+
-H "Content-Type: application/json" \
83+
-H "Authorization: Bearer YOUR_ANTHROPIC_API_KEY" \
84+
-H "Helicone-Auth: Bearer YOUR_HELICONE_API_KEY" \
85+
-H "Helicone-Target-Url: https://api.anthropic.com" \
86+
-d '{
87+
"model": "claude-3-5-sonnet-20241022:online",
88+
"messages": [
89+
{
90+
"role": "user",
91+
"content": "What are the latest developments in AI?"
92+
}
93+
]
94+
}'
95+
```
96+
</Tab>
97+
</Tabs>
98+
99+
## Advanced Configuration
100+
101+
You can customize the web search behavior by including a `plugins` parameter in your request body:
102+
103+
```json
104+
{
105+
"model": "claude-3-5-sonnet-20241022:online",
106+
"messages": [...],
107+
"plugins": [
108+
{
109+
"id": "web",
110+
"max_uses": 5,
111+
"allowed_domains": ["wikipedia.org", "arxiv.org"],
112+
"blocked_domains": ["example.com"],
113+
"user_location": {
114+
"type": "approximate",
115+
"country": "US"
116+
}
117+
}
118+
]
119+
}
120+
```
121+
122+
### Plugin Options
123+
124+
| Parameter | Type | Description |
125+
|-----------|------|-------------|
126+
| `max_uses` | integer | Maximum number of web searches allowed per request (default: unlimited) |
127+
| `allowed_domains` | array | Restrict searches to specific domains |
128+
| `blocked_domains` | array | Exclude specific domains from search results |
129+
| `user_location` | object | Provide approximate user location for localized results |
130+
131+
## Response Format
132+
133+
When web search is used, the response includes annotations with citation information:
134+
135+
```json
136+
{
137+
"choices": [
138+
{
139+
"message": {
140+
"role": "assistant",
141+
"content": "Based on recent developments, AI has made significant progress in...",
142+
"annotations": [
143+
{
144+
"type": "url_citation",
145+
"url_citation": {
146+
"url": "https://example.com/article",
147+
"title": "Recent AI Breakthroughs",
148+
"content": "The source text that was cited...",
149+
"start_index": 0,
150+
"end_index": 67
151+
}
152+
}
153+
]
154+
}
155+
}
156+
]
157+
}
158+
```
159+
160+
### Understanding Annotations
161+
162+
- **`url`**: The source URL of the cited information
163+
- **`title`**: The title of the source page
164+
- **`content`**: The relevant excerpt from the source
165+
- **`start_index`**: Character position where the citation begins in the response
166+
- **`end_index`**: Character position where the citation ends in the response
167+
168+
## Pricing
169+
170+
Web search requests are billed at standard Anthropic rates plus any additional costs for web search usage. The usage statistics include:
171+
172+
```json
173+
{
174+
"usage": {
175+
"input_tokens": 1000,
176+
"output_tokens": 500,
177+
"server_tool_use": {
178+
"web_search_requests": 1
179+
}
180+
}
181+
}
182+
```
183+
184+
## Related Features
185+
186+
- [Gateway Integration](/getting-started/integration-method/gateway)
187+
- [Gateway Fallbacks](/getting-started/integration-method/gateway-fallbacks)
188+
- [Caching](/features/advanced-usage/caching)
189+
- [Custom Headers](/helicone-headers/helicone-auth)

docs/swagger.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3311,6 +3311,35 @@
33113311
"start_timestamp": {
33123312
"type": "string"
33133313
},
3314+
"annotations": {
3315+
"items": {
3316+
"properties": {
3317+
"content": {
3318+
"type": "string"
3319+
},
3320+
"title": {
3321+
"type": "string"
3322+
},
3323+
"url": {
3324+
"type": "string"
3325+
},
3326+
"type": {
3327+
"type": "string",
3328+
"enum": [
3329+
"url_citation"
3330+
],
3331+
"nullable": false
3332+
}
3333+
},
3334+
"required": [
3335+
"title",
3336+
"url",
3337+
"type"
3338+
],
3339+
"type": "object"
3340+
},
3341+
"type": "array"
3342+
},
33143343
"reasoning": {
33153344
"type": "string"
33163345
},
@@ -8158,6 +8187,13 @@
81588187
"verbosity"
81598188
]
81608189
},
8190+
"PluginId": {
8191+
"type": "string",
8192+
"enum": [
8193+
"web"
8194+
],
8195+
"nullable": false
8196+
},
81618197
"RateLimits": {
81628198
"properties": {
81638199
"rpm": {
@@ -8369,6 +8405,12 @@
83698405
},
83708406
"type": "array"
83718407
},
8408+
"supportedPlugins": {
8409+
"items": {
8410+
"$ref": "#/components/schemas/PluginId"
8411+
},
8412+
"type": "array"
8413+
},
83728414
"rateLimits": {
83738415
"$ref": "#/components/schemas/RateLimits"
83748416
},

0 commit comments

Comments
 (0)