### Python Example for Image Search Source: https://documentation.you.com/api-reference/images/images_explorer=true Shows a Python example for executing an image search. It utilizes the 'requests' library to send a GET request with appropriate headers and URL parameters. ```python import requests api_key = '' query = 'The image you are searching for' url = 'https://image-search.ydc-index.io/images' headers = { 'X-API-Key': api_key } params = { 'q': query } response = requests.get(url, headers=headers, params=params) if response.status_code == 200: print(response.json()) else: print(f'Error: {response.status_code}') ``` -------------------------------- ### Python: Fetch Live News Example Source: https://documentation.you.com/api-reference/live-news/live-news_explorer=true A Python script demonstrating how to retrieve live news articles. It utilizes the `requests` library to send a GET request with the necessary API key and query parameters. ```python import requests def get_live_news(query: str, api_key: str, count: int = None): url = "https://api.ydc-index.io/livenews" headers = { "X-API-Key": api_key } params = { "q": query } if count: params["count"] = count try: response = requests.get(url, headers=headers, params=params) response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx) return response.json() except requests.exceptions.RequestException as e: print(f"Error fetching live news: {e}") return None # Example Usage: # api_key = "YOUR_API_KEY" # news_data = get_live_news("Your query about news", api_key, count=5) # if news_data: # print(news_data) ``` -------------------------------- ### Fetch Live News Data using Go Source: https://documentation.you.com/api-reference/live-news/live-news Provides a Go code example for fetching live news data. It constructs an HTTP GET request to the Live News API, setting the necessary API key and query parameters. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.ydc-index.io/livenews?q=Your+query+about+news" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("X-API-Key", "") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### TypeScript: Fetch Live News Example Source: https://documentation.you.com/api-reference/live-news/live-news_explorer=true Illustrative TypeScript code for fetching live news. This example uses the fetch API to make a GET request to the Live News endpoint, including the API key and query parameters. ```typescript async function getLiveNews(query: string, apiKey: string, count?: number): Promise { let url = `https://api.ydc-index.io/livenews?q=${encodeURIComponent(query)}`; if (count) { url += `&count=${count}`; } const response = await fetch(url, { method: 'GET', headers: { 'X-API-Key': apiKey } }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } return await response.json(); } // Example Usage: // const apiKey = "YOUR_API_KEY"; // getLiveNews("Your query about news", apiKey, 10) // .then(data => console.log(data)) // .catch(error => console.error('Error fetching live news:', error)); ``` -------------------------------- ### Search You API using Java SDK Source: https://documentation.you.com/api-reference/search/v1-search An example of how to call the You API's search functionality using Java with the Unirest library. This snippet shows setting the API key and making a GET request, returning the response as a String. Requires the Unirest library dependency. ```java HttpResponse response = Unirest.get("https://ydc-index.io/v1/search?query=Your+query") .header("X-API-Key", "") .asString(); ``` -------------------------------- ### Search You API using C# SDK Source: https://documentation.you.com/api-reference/search/v1-search Illustrates how to use the RestSharp library in C# to perform a search on the You API. This example configures the API key header and executes a GET request, returning the IRestResponse. Ensure RestSharp is added as a project dependency. ```csharp var client = new RestClient("https://ydc-index.io/v1/search?query=Your+query"); var request = new RestRequest(Method.GET); request.AddHeader("X-API-Key", ""); IRestResponse response = client.Execute(request); ``` -------------------------------- ### TypeScript Example for Image Search Source: https://documentation.you.com/api-reference/images/images_explorer=true Provides a TypeScript example for making an image search request. This snippet demonstrates how to construct the request URL, set headers, and send the request. ```typescript fetch('https://image-search.ydc-index.io/images', { method: 'GET', headers: { 'X-API-Key': '', 'Content-Type': 'application/x-www-form-urlencoded' }, body: new URLSearchParams({ 'q': 'The image you are searching for' }) }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` -------------------------------- ### Fetch Live News Data using Swift Source: https://documentation.you.com/api-reference/live-news/live-news Provides a Swift example for accessing live news data. It uses URLSession to perform a GET request to the Live News API, including the API key in the request headers. ```swift import Foundation let headers = ["X-API-Key": ""] let request = NSMutableURLRequest(url: NSURL(string: "https://api.ydc-index.io/livenews?q=Your+query+about+news")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` -------------------------------- ### Search You API using Swift SDK Source: https://documentation.you.com/api-reference/search/v1-search A Swift code example demonstrating a search request to the You API using URLSession. It shows how to set up the request with the API key and handle the response asynchronously. Useful for iOS and macOS development. ```swift import Foundation let headers = ["X-API-Key": ""] let request = NSMutableURLRequest(url: NSURL(string: "https://ydc-index.io/v1/search?query=Your+query")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` -------------------------------- ### Fetch Live News Data using JavaScript Source: https://documentation.you.com/api-reference/live-news/live-news Shows how to retrieve live news data using JavaScript's fetch API. This example makes a GET request to the Live News API, including query parameters and an API key in the headers. ```javascript const url = 'https://api.ydc-index.io/livenews?q=Your+query+about+news'; const options = {method: 'GET', headers: {'X-API-Key': ''}}; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` -------------------------------- ### cURL: Fetch Live News Source: https://documentation.you.com/api-reference/live-news/live-news_explorer=true Example of how to fetch live news using cURL. It demonstrates setting the API key and passing a query parameter. The endpoint is `https://api.ydc-index.io/livenews`. ```curl curl -G https://api.ydc-index.io/livenews \ -H "X-API-Key: " \ --data-urlencode "q=Your query about news" ``` -------------------------------- ### Make Image Search API Request (Go) Source: https://documentation.you.com/api-reference/images/images This Go code snippet illustrates how to make an HTTP GET request to the image search API. It defines the API endpoint, creates a new GET request, adds the 'X-API-Key' header, and executes the request using the default HTTP client. The response status and body are then printed. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://image-search.ydc-index.io/images?q=The+image+you+are+searching+for" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("X-API-Key", "") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Fetch Live News Data using C# Source: https://documentation.you.com/api-reference/live-news/live-news Presents a C# code example for retrieving live news data using the RestSharp library. It makes a GET request to the Live News API, adding the API key to the request headers. ```csharp var client = new RestClient("https://api.ydc-index.io/livenews?q=Your+query+about+news"); var request = new RestRequest(Method.GET); request.AddHeader("X-API-Key", ""); IRestResponse response = client.Execute(request); ``` -------------------------------- ### Python Search Request Source: https://documentation.you.com/api-reference/search/v1-search_explorer=true This snippet provides a Python example for making a search request to the API. It uses the `requests` library to send a GET request, including the API key in the headers and the search query as a URL-encoded parameter. This is a common approach for server-side integrations. ```python import requests api_key = "" query = "Your query" params = { "query": query } headers = { "X-API-Key": api_key } response = requests.get("https://ydc-index.io/v1/search", params=params, headers=headers) data = response.json() print(data) ``` -------------------------------- ### Search You API using Python SDK Source: https://documentation.you.com/api-reference/search/v1-search Demonstrates how to perform a search query against the You API using the Python requests library. It includes setting the API key, defining the query parameters, and printing the JSON response. Requires the 'requests' library to be installed. ```python import requests url = "https://ydc-index.io/v1/search" querystring = {"query":"Your query"} headers = {"X-API-Key": ""} response = requests.get(url, headers=headers, params=querystring) print(response.json()) ``` -------------------------------- ### JSON Response for Live News Source: https://documentation.you.com/api-reference/live-news/live-news_explorer=true Example of a successful JSON response when retrieving live news. It includes details about the query, a list of news results with their descriptions, URLs, and metadata. ```json { "news": { "query": { "original": "Your query about news", "spellcheck_off": false }, "results": [ { "age": "6h", "description": "Any news for you!", "meta_url": { "hostname": "www.wsj.com", "netloc": "wsj.com", "path": "> world > china-to-block-its-rare-earth-experts-from-spilling-their-secrets-8d69b75f", "scheme": "https" }, "page_age": "2025-06-25T11:41:00", "source_name": "WSJ", "thumbnail": { "src": "https://images.wsj.net/im-42431776?width=700&height=449" }, "title": "Exclusive | China Is Tracking Down Its Rare-Earth Experts—and Taking Away Passports", "type": "news_result", "url": "https://www.wsj.com/world/china-to-block-its-rare-earth-experts-from-spilling-their-secrets-8d69b75f?gaa_at=eafs&gaa_n=ASWzDAiVjqRNxFmx5h0MkVKtlAuVL0B8yQIDw3q7BheARNdP_8kbbzG50lB9&gaa_ts=685c3985&gaa_sig=x_9tkHwj_WnP29wU-sgBvg0clotjEVKnMak6vgU98b6mdtl5vl0Iu8k96Ep4H_YZRrt-38wFlodzzWcHrWYNWQ%3D%3D", "metadata": {}, "article_id": "string" } ], "type": "news", "metadata": { "request_uuid": "942ccbdd-7705-4d9c-9d37-4ef386658e90" } } } ``` -------------------------------- ### GET /v1/search Source: https://documentation.you.com/api-reference/search/v1-search This endpoint allows you to perform searches. It accepts a query parameter and requires an API key for authentication. ```APIDOC ## GET /v1/search ### Description This endpoint allows you to perform searches against the index. You need to provide a query string and authenticate using an API key. ### Method GET ### Endpoint https://ydc-index.io/v1/search ### Parameters #### Query Parameters - **query** (string) - Required - The search term. #### Headers - **X-API-Key** (string) - Required - Your API key for authentication. ### Request Example ``` GET https://ydc-index.io/v1/search?query=Your+query Headers: X-API-Key: ``` ### Response #### Success Response (200) - **results** (array) - A list of search results. - **count** (integer) - The total number of results. #### Response Example ```json { "results": [ { "url": "http://example.com", "title": "Example Title", "description": "This is an example description." } ], "count": 1 } ``` ``` -------------------------------- ### Search You API using Go SDK Source: https://documentation.you.com/api-reference/search/v1-search Provides a Go code snippet to query the You API. It demonstrates making an HTTP GET request, setting the necessary API key header, and reading the response body. Ensure proper error handling for production use. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://ydc-index.io/v1/search?query=Your+query" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("X-API-Key", "") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Make a Search Request using cURL Source: https://documentation.you.com/api-reference/index This example demonstrates how to perform a search query using the cURL command-line tool. It includes the necessary endpoint URL, API key header, and the 'query' data parameter. The response structure is also provided as a JSON object. ```Bash $| curl -G https://ydc-index.io/v1/search \ ---|--- >| -H "X-API-Key: " \ >| --data-urlencode "query=Your query" ``` ```JSON 1| { ---|--- 2| "results": { 3| "web": [ 4| { 5| "url": "https://you.com", 6| "title": "The World's Greatest Search Engine!", 7| "description": "Search on YDC", 8| "snippets": [ 9| "I'm an AI assistant that helps you get more done. What can I help you with?" 10| ], 11| "thumbnail_url": "https://www.somethumbnailsite.com/thumbnail.jpg", 12| "page_age": "2025-06-25T11:41:00", 13| "authors": [ 14| "John Doe" 15| ], 16| "favicon_url": "https://someurl.com/favicon" 17| } 18| ], 19| "news": [ 20| { 21| "title": "Exclusive | You.com becomes the backbone of the EU's AI strategy", 22| "description": "As the EU's AI strategy is being debated, You.com becomes the backbone of the EU's AI strategy.", 23| "page_age": "2025-06-25T11:41:00", 24| "thumbnail_url": "https://www.somethumbnailsite.com/thumbnail.jpg", 25| "url": "https://www.you.com/news/eu-ai-strategy-youcom" 26| } 27| ] 28| }, 29| "metadata": { 30| "request_uuid": "942ccbdd-7705-4d9c-9d37-4ef386658e90", 31| "query": "Your query", 32| "latency": 0.123 33| } 34| } ``` -------------------------------- ### GET /livenews Source: https://documentation.you.com/api-reference/live-news/live-news_explorer=true Retrieves live news articles based on a query. Requires an X-API-Key for authentication. You can specify the query parameter 'q' and optionally 'count' for the number of results. ```APIDOC ## GET /livenews ### Description Retrieves live news articles based on a query. ### Method GET ### Endpoint https://api.ydc-index.io/livenews ### Parameters #### Query Parameters - **q** (string) - Required - Defaults to `Your query about news`. Retrieves responses from news media websites that are relevant to the user’s query. - **count** (integer) - Optional - `1-40`. Specifies the maximum number of news results to return. ### Request Example ```bash curl -G https://api.ydc-index.io/livenews \ -H "X-API-Key: " \ --data-urlencode "q=Your query about news" ``` ### Response #### Success Response (200) - **news** (object or null) - A JSON object containing news results. - **query** (object) - **original** (string) - The original query string. - **spellcheck_off** (boolean) - Indicates if spellcheck was turned off. - **results** (array) - An array of news result objects. - **age** (string) - The age of the news article (e.g., '6h'). - **description** (string) - A brief description of the news article. - **meta_url** (object) - Metadata about the URL. - **hostname** (string) - **netloc** (string) - **path** (string) - **scheme** (string) - **page_age** (string) - The age of the page in ISO 8601 format. - **source_name** (string) - The name of the source. - **thumbnail** (object) - Thumbnail image details. - **src** (string) - URL of the thumbnail image. - **title** (string) - The title of the news article. - **type** (string) - The type of the result (e.g., 'news_result'). - **url** (string) - The URL of the news article. - **metadata** (object) - Additional metadata for the result. - **article_id** (string) - Unique identifier for the article. - **type** (string) - The type of the response (e.g., 'news'). - **metadata** (object) - **request_uuid** (string) - Unique identifier for the request. #### Response Example ```json { "news": { "query": { "original": "Your query about news", "spellcheck_off": false }, "results": [ { "age": "6h", "description": "Any news for you!", "meta_url": { "hostname": "www.wsj.com", "netloc": "wsj.com", "path": "> world > china-to-block-its-rare-earth-experts-from-spilling-their-secrets-8d69b75f", "scheme": "https" }, "page_age": "2025-06-25T11:41:00", "source_name": "WSJ", "thumbnail": { "src": "https://images.wsj.net/im-42431776?width=700&height=449" }, "title": "Exclusive | China Is Tracking Down Its Rare-Earth Experts—and Taking Away Passports", "type": "news_result", "url": "https://www.wsj.com/world/china-to-block-its-rare-earth-experts-from-spilling-their-secrets-8d69b75f?gaa_at=eafs&gaa_n=ASWzDAiVjqRNxFmx5h0MkVKtlAuVL0B8yQIDw3q7BheARNdP_8kbbzG50lB9&gaa_ts=685c3985&gaa_sig=x_9tkHwj_WnP29wU-sgBvg0clotjEVKnMak6vgU98b6mdtl5vl0Iu8k96Ep4H_YZRrt-38wFlodzzWcHrWYNWQ%3D%3D", "metadata": {}, "article_id": "string" } ], "type": "news", "metadata": { "request_uuid": "942ccbdd-7705-4d9c-9d37-4ef386658e90" } } } ``` ### Errors - **401**: Unauthorized Error - **403**: Forbidden Error - **500**: Internal Server Error ### Authentication - **X-API-Key**: A unique API Key is required to authorize API access. For details, see how to get your API Key. ``` -------------------------------- ### In-depth Error Explanations Source: https://documentation.you.com/api-reference/errors This section provides detailed explanations for specific error codes, including common scenarios and example error response bodies. ```APIDOC ## In-depth Error Explanations ### 401 Unauthorized This error can occur due to several authentication-related issues: * **Missing API Key**: The `detail` field will indicate `API key is required`. * **Invalid or Expired API Key**: The `detail` field will indicate `Invalid or expired API key`. * **Other Auth Parsing Errors**: A generic error message will be provided in the `detail` field. ```json { "detail": "API key is required" } ``` ### 403 Forbidden This error signifies that your API key lacks the necessary permissions or scopes to access a particular resource or endpoint. * **Missing Scopes**: For example, attempting to access `/v1/contents` without the correct scope will result in `Missing required scopes`. ```json { "detail": "Missing required scopes" } ``` ### 404 Not Found This error indicates that the requested resource or agent does not exist or is no longer available. * **Agent Not Found**: The specified agent ID does not exist or has been deleted. * **Agent Not Supported Yet**: The agent uses a model or feature that is not yet supported. ```json { "detail": "agent_not_found" } ``` ```json { "detail": "agent_not_supported_yet" } ``` ### 500 Internal Server Error (Auth/Authorization Middleware) These errors occur within the API's internal authentication or authorization middleware. * **Authentication Failure**: `Internal authentication error`. * **Authorization Failure**: `Internal authorization error`. ```json { "detail": "Internal authentication error" } ``` ```json { "detail": "Internal authorization error" } ``` ``` -------------------------------- ### GET Images Endpoint Source: https://documentation.you.com/api-reference/images/images This snippet shows the basic structure of a GET request to the You.com Image Search API. It includes the base URL and the required query parameter 'q' for the search term and 'X-API-Key' for authentication. The response is expected to be a JSON object containing image search results. ```HTTP GET https://image-search.ydc-index.io/images?q=your_search_query Host: image-search.ydc-index.io X-API-Key: YOUR_API_KEY ``` -------------------------------- ### Get Live News using OpenAPI Specification Source: https://documentation.you.com/api-reference/live-news/live-news This OpenAPI specification defines the structure and parameters for the Live News API endpoint. It details the GET request for '/livenews', including query parameters like 'q' (search query) and 'count' (number of results), and the 'X-API-Key' header for authentication. The specification also outlines the structure of the JSON response for successful requests (200 OK) and potential error responses (401, 403, 500). ```yaml openapi: 3.1.1 info: title: Returns a list of live news from query version: endpoint_.returnsAListOfLiveNewsFromQuery paths: /livenews: get: operationId: returns-a-list-of-live-news-from-query summary: Returns a list of live news from query tags: [] parameters: - name: q in: query description: >- Retrieves responses from news media websites that are relevant to the user's query. **NOTE**: The You.com news API is currently available to exclusive early access partners. To express interest in early access, please reach out via email to [api@you.com](mailto:api@you.com). required: true schema: type: string - name: count in: query description: Specifies the maximum number of news results to return. required: false schema: type: integer - name: X-API-Key in: header description: Header authentication of the form `undefined ` required: true schema: type: string responses: '200': description: A JSON object containing news results. content: application/json: schema: $ref: >- #/components/schemas/returnsAListOfLiveNewsFromQuery_Response_200 '401': description: Unauthorized. Problems with API key. content: {} '403': description: Forbidden. API key lacks scope for this path. content: {} '500': description: >- Internal Server Error during authentication/authorization middleware. content: {} components: schemas: LivenewsGetResponsesContentApplicationJsonSchemaNewsQuery: type: object properties: original: type: string spellcheck_off: type: boolean LivenewsGetResponsesContentApplicationJsonSchemaNewsResultsItemsMetaUrl: type: object properties: hostname: type: string netloc: type: string path: type: string scheme: type: string LivenewsGetResponsesContentApplicationJsonSchemaNewsResultsItemsThumbnail: type: object properties: src: type: string format: uri LivenewsGetResponsesContentApplicationJsonSchemaNewsResultsItemsMetadata: type: object properties: {} LivenewsGetResponsesContentApplicationJsonSchemaNewsResultsItems: type: object properties: age: type: string description: type: string meta_url: $ref: >- #/components/schemas/LivenewsGetResponsesContentApplicationJsonSchemaNewsResultsItemsMetaUrl page_age: type: string format: date-time source_name: type: string thumbnail: $ref: >- #/components/schemas/LivenewsGetResponsesContentApplicationJsonSchemaNewsResultsItemsThumbnail title: type: string type: type: string url: type: string format: uri metadata: $ref: >- #/components/schemas/LivenewsGetResponsesContentApplicationJsonSchemaNewsResultsItemsMetadata article_id: type: - string - 'null' LivenewsGetResponsesContentApplicationJsonSchemaNewsMetadata: type: object properties: request_uuid: type: string format: uuid LivenewsGetResponsesContentApplicationJsonSchemaNews: type: object properties: query: $ref: >- #/components/schemas/LivenewsGetResponsesContentApplicationJsonSchemaNewsQuery results: type: array items: $ref: >- #/components/schemas/LivenewsGetResponsesContentApplicationJsonSchemaNewsResultsItems type: type: string metadata: $ref: >- #/components/schemas/LivenewsGetResponsesContentApplicationJsonSchemaNewsMetadata returnsAListOfLiveNewsFromQuery_Response_200: type: object properties: news: $ref: >- #/components/schemas/LivenewsGetResponsesContentApplicationJsonSchemaNews ``` -------------------------------- ### Make Image Search API Request (C#) Source: https://documentation.you.com/api-reference/images/images This C# code snippet utilizes the RestSharp library to send a GET request to the image search API. It configures the client with the API endpoint, creates a GET request, adds the 'X-API-Key' header, and executes the request, storing the response. ```csharp var client = new RestClient("https://image-search.ydc-index.io/images?q=The+image+you+are+searching+for"); var request = new RestRequest(Method.GET); request.AddHeader("X-API-Key", ""); IRestResponse response = client.Execute(request); ``` -------------------------------- ### Search You API using JavaScript (Node.js/Browser) Source: https://documentation.you.com/api-reference/search/v1-search Shows how to make a search request to the You API using the Fetch API in JavaScript. This example covers setting the API key and handling the JSON response or any potential errors. Suitable for both Node.js and browser environments. ```javascript const url = 'https://ydc-index.io/v1/search?query=Your+query'; const options = {method: 'GET', headers: {'X-API-Key': ''}}; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` -------------------------------- ### Fetch Live News Data using Java Source: https://documentation.you.com/api-reference/live-news/live-news Illustrates fetching live news data in Java using the Unirest library. This snippet sends a GET request to the Live News API, including the API key as a header. ```java HttpResponse response = Unirest.get("https://api.ydc-index.io/livenews?q=Your+query+about+news") .header("X-API-Key", "") .asString(); ``` -------------------------------- ### Make Image Search API Request (Swift) Source: https://documentation.you.com/api-reference/images/images This Swift code snippet demonstrates how to make a GET request to the image search API using URLSession. It sets up the URL, headers including the API key, and creates a data task to execute the request. The response is handled in a completion handler. ```swift import Foundation let headers = ["X-API-Key": ""] let request = NSMutableURLRequest(url: NSURL(string: "https://image-search.ydc-index.io/images?q=The+image+you+are+searching+for")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` -------------------------------- ### Example Image Search JSON Response Source: https://documentation.you.com/api-reference/images/images_explorer=true Illustrates the structure of a successful JSON response from the image search API. It contains a list of image results, each with a title, page URL, and image URL, along with query metadata. ```json { "images": { "results": [ { "title": "8 Test Day Tips for Success", "page_url": "https://www.c2educate.com/8-test-day-tips-success/", "image_url": "https://s26378.pcdn.co/wp-content/uploads/sat-or-act-test-1030x519.jpg" } ] }, "metadata": { "query": "The image you are searching for", "search_uuid": "c6c8f8cf-b6fc-4248-9828-24fc0dcf7be5" } } ``` -------------------------------- ### GET /v1/search Source: https://documentation.you.com/api-reference/search/v1-search Returns a list of unified search results from web and news sources based on a user's query. This endpoint is suitable for feeding LLMs with relevant information. ```APIDOC ## GET /v1/search ### Description This endpoint returns LLM-ready web and news results based on a user's query. It uses a classification mechanism to distinguish between web results and news articles. This is ideal for queries like 'What is the weather like in France in September?' to feed into an LLM. **WARNING**: For Bearer token authentication with Databricks Unity Catalog, use the `/v2/search` endpoint instead of `/search`. ### Method GET ### Endpoint /v1/search ### Parameters #### Query Parameters - **query** (string) - Required - The search query used to retrieve relevant results from the web. Search operators can also be included. - **count** (integer) - Optional - Specifies the maximum number of search results to return per section (web and news). - **freshness** (string) - Optional - Specifies the freshness of the results. Accepts `day`, `week`, `month`, `year`, or a date range string like `YYYY-MM-DDtoYYYY-MM-DD`. If the query includes a temporal keyword, the broader timeframe between the query and the `freshness` parameter will be used. - **offset** (integer) - Optional - Indicates the offset for pagination, calculated in multiples of `count`. Range `0 ≤ offset ≤ 9`. - **country** (string) - Optional - The country code that determines the geographical focus of the web results. - **language** (string) - Optional - The language of the web results to be returned (BCP 47 format). - **safesearch** (string) - Optional - Configures the safesearch filter for content moderation (e.g., to return or exclude NSFW content). - **livecrawl** (string) - Optional - Indicates which section(s) of search results to livecrawl and return full page content. - **livecrawl_formats** (string) - Optional - Indicates the format of the livecrawled content. #### Header Parameters - **X-API-Key** (string) - Required - Header authentication of the form `undefined ` ### Request Example ```json { "query": "latest AI advancements", "count": 10, "freshness": "week", "country": "US", "language": "en" } ``` ### Response #### Success Response (200) - **web** (array) - Search results from web sources. - **news** (array) - Search results from news sources. #### Response Example ```json { "web": [ { "title": "New AI Model Achieves State-of-the-Art Performance", "url": "https://example.com/ai-news", "snippet": "Researchers have developed a new AI model that significantly outperforms existing models in natural language processing tasks." } ], "news": [ { "title": "Global AI Conference Highlights", "url": "https://example.com/global-ai-conf", "snippet": "Key takeaways from the recent global AI conference, focusing on advancements in machine learning and ethics." } ] } ``` #### Error Responses - **401** - Unauthorized. Problems with API key. - **403** - Forbidden. API key lacks scope for this path. - **500** - Internal Server Error. ``` -------------------------------- ### Fetch Live News Data using Python Source: https://documentation.you.com/api-reference/live-news/live-news Demonstrates how to fetch live news data using the Python requests library. It sends a GET request to the Live News API endpoint with specified query parameters and an API key. ```python import requests url = "https://api.ydc-index.io/livenews" querystring = {"q":"Your query about news"} headers = {"X-API-Key": ""} response = requests.get(url, headers=headers, params=querystring) print(response.json()) ``` -------------------------------- ### GET /v1/search Source: https://documentation.you.com/api-reference/search/v1-search_explorer=true This endpoint returns LLM-ready web results based on a user’s query. It can return web results and news associated with the query. It's ideal for queries that require temporal information or specific classification. ```APIDOC ## GET /v1/search ### Description This endpoint returns LLM-ready web results based on a user’s query. It can return web results and news associated with the query. It's ideal for queries that require temporal information or specific classification. ### Method GET ### Endpoint https://ydc-index.io/v1/search ### Parameters #### Query Parameters - **query** (string) - Required - The search query used to retrieve relevant results from the web. You can also include search operators to refine your search. - **count** (integer) - Optional - Specifies the maximum number of search results to return per section (web and news). Defaults to `10`. Range: `1-100`. - **freshness** (string) - Optional - Specifies the freshness of the results to return. Acceptable values: `day`, `week`, `month`, `year`, or a date range string in the format `YYYY-MM-DDtoYYYY-MM-DD`. - **offset** (integer) - Optional - Indicates the `offset` for pagination. The `offset` is calculated in multiples of `count`. Range: `0 ≤ offset ≤ 9`. - **country** (enum) - Optional - The country code that determines the geographical focus of the web results. - **language** (enum) - Optional - The language of the web results that will be returned (BCP 47 format). Defaults to `EN`. - **safesearch** (enum) - Optional - Configures the safesearch filter for content moderation. Allowed values: `off`, `moderate`, `strict`. - **livecrawl** (enum) - Optional - Indicates which section(s) of search results to livecrawl and return full page content. Allowed values: `web`, `news`, `all`. - **livecrawl_formats** (enum) - Optional - Indicates the format of the livecrawled content. Allowed values: `html`, `markdown`. ### Authentication - **X-API-Key** (string) - Required - A unique API Key is required to authorize API access. ### Request Example ```bash curl -G https://ydc-index.io/v1/search \ -H "X-API-Key: " \ --data-urlencode "query=Your query" ``` ### Response #### Success Response (200) A JSON object containing unified search results from web and news sources. - **results** (object or null) - Contains search results from web and news sections. - **metadata** (object or null) - Contains metadata about the request, including `request_uuid`, `query`, and `latency`. #### Response Example ```json { "results": { "web": [ { "url": "https://you.com", "title": "The World's Greatest Search Engine!", "description": "Search on YDC", "snippets": [ "I'm an AI assistant that helps you get more done. What can I help you with?" ], "thumbnail_url": "https://www.somethumbnailsite.com/thumbnail.jpg", "page_age": "2025-06-25T11:41:00", "authors": [ "John Doe" ], "favicon_url": "https://someurl.com/favicon" } ], "news": [ { "title": "Exclusive | You.com becomes the backbone of the EU's AI strategy", "description": "As the EU's AI strategy is being debated, You.com becomes the backbone of the EU's AI strategy.", "page_age": "2025-06-25T11:41:00", "thumbnail_url": "https://www.somethumbnailsite.com/thumbnail.jpg", "url": "https://www.you.com/news/eu-ai-strategy-youcom" } ] }, "metadata": { "request_uuid": "942ccbdd-7705-4d9c-9d37-4ef386658e90", "query": "Your query", "latency": 0.123 } } ``` ### Errors - **401**: Unauthorized Error - **403**: Forbidden Error - **500**: Internal Server Error ``` -------------------------------- ### cURL Request for Image Search Source: https://documentation.you.com/api-reference/images/images_explorer=true Demonstrates how to perform an image search using a cURL request. It includes the necessary GET endpoint, API key header, and URL-encoded query parameter. ```curl curl -G https://image-search.ydc-index.io/images \ -H "X-API-Key: " \ --data-urlencode "q=The image you are searching for" ``` -------------------------------- ### cURL Search Request Source: https://documentation.you.com/api-reference/search/v1-search_explorer=true This snippet demonstrates how to make a GET request to the search API using cURL. It includes the necessary API endpoint, the 'X-API-Key' header for authentication, and the 'query' parameter, which is essential for specifying the search term. The query is URL-encoded to ensure proper transmission. ```bash $ curl -G https://ydc-index.io/v1/search \ -H "X-API-Key: " \ --data-urlencode "query=Your query" ``` -------------------------------- ### Make Image Search API Request (JavaScript) Source: https://documentation.you.com/api-reference/images/images This JavaScript code snippet shows how to perform a GET request to the image search API using the 'fetch' API. It constructs the URL with the search query and sets the 'X-API-Key' header. The response is parsed as JSON and logged to the console, with error handling included. ```javascript const url = 'https://image-search.ydc-index.io/images?q=The+image+you+are+searching+for'; const options = {method: 'GET', headers: {'X-API-Key': ''}}; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` -------------------------------- ### Make Image Search API Request (Python) Source: https://documentation.you.com/api-reference/images/images This Python code snippet demonstrates how to make a GET request to the image search API using the 'requests' library. It includes setting the API endpoint, query parameters, and the necessary API key header. The response is then printed as JSON. ```python import requests url = "https://image-search.ydc-index.io/images" querystring = {"q":"The image you are searching for"} headers = {"X-API-Key": ""} response = requests.get(url, headers=headers, params=querystring) print(response.json()) ``` -------------------------------- ### Make Image Search API Request (Java) Source: https://documentation.you.com/api-reference/images/images This Java code snippet uses the Unirest library to make a GET request to the image search API. It sets the API endpoint and the 'X-API-Key' header, then executes the request and retrieves the response as a String. ```java HttpResponse response = Unirest.get("https://image-search.ydc-index.io/images?q=The+image+you+are+searching+for") .header("X-API-Key", "") .asString(); ``` -------------------------------- ### GET /livenews Source: https://documentation.you.com/api-reference/live-news/live-news Retrieve live news based on a query. ```APIDOC ## GET /livenews ### Description This endpoint retrieves live news articles based on a search query. ### Method GET ### Endpoint https://api.ydc-index.io/livenews ### Parameters #### Query Parameters - **q** (string) - Required - The search query for news articles. #### Headers - **X-API-Key** (string) - Required - Your API key for authentication. ### Request Example ``` GET https://api.ydc-index.io/livenews?q=Your+query+about+news Host: api.ydc-index.io X-API-Key: ``` ### Response #### Success Response (200) - **news** (array) - A list of news articles matching the query. - Each article object may contain fields like `title`, `url`, `source`, `published_at`, etc. #### Response Example ```json { "news": [ { "title": "Example News Title", "url": "https://example.com/news/article", "source": "Example News Source", "published_at": "2023-10-27T10:00:00Z" } ] } ``` ```