Web Search

Access real-time information from the web using Selam API's integrated web search capabilities.

Overview

Selam API provides real-time web search capabilities through integration with SearXNG, allowing any model to access current information from the web. The search feature includes load balancing across multiple endpoints, automatic health checking, and seamless fallback for high reliability.

🚀 High Performance

20M+ searches per day capacity with load balancing

🔄 Automatic Fallback

Seamless failover between endpoints for reliability

📡 Streaming Support

Works with both streaming and non-streaming responses

🎯 Smart Detection

Automatically skips for models with built-in search

How It Works

When you include tools=[{type: "web_search"}] in your request:

  1. The system checks if the model has built-in search capabilities
  2. If not, it executes a web search using your query
  3. Search results are formatted and injected into the context
  4. The model processes your request with access to current web information
  5. The response includes citations to sources when appropriate

Basic Usage

1from openai import OpenAI
2
3client = OpenAI(
4    api_key="your-api-key",
5    base_url="https://api.selamgpt.com/v1"
6)
7
8# Enable web search with tools parameter
9response = client.chat.completions.create(
10    model="selam-turbo",
11    messages=[{
12        "role": "user",
13        "content": "What are the latest AI developments from last week?"
14    }],
15    tools=[{"type": "web_search"}]  # Enable web search
16)
17
18print(response.choices[0].message.content)

Streaming with Web Search

Web search works seamlessly with streaming responses:

1response = client.chat.completions.create(
2    model="selam-turbo",
3    messages=[{
4        "role": "user",
5        "content": "What's happening in quantum computing?"
6    }],
7    tools=[{"type": "web_search"}],
8    stream=True  # Streaming enabled
9)
10
11for chunk in response:
12    if chunk.choices[0].delta.content:
13        print(chunk.choices[0].delta.content, end="")

Built-in Search Models

Information

Some models have native search capabilities and don't need the web_search tool.

The following models have built-in search and automatically access web information:

  • selam-search - Selam's search-optimized model
  • gpt-4o-search-preview - OpenAI's search model
  • gpt-4-search - GPT-4 with search
  • perplexity - Perplexity AI models
  • you-search - You.com search models
1# No tools parameter needed for built-in search models
2response = client.chat.completions.create(
3    model="selam-search",  # Has built-in search
4    messages=[{
5        "role": "user",
6        "content": "Latest AI news"
7    }]
8    # No tools parameter!
9)

Multi-turn Conversations

You can use web search in multi-turn conversations. The search context is maintained throughout the conversation:

1messages = [
2    {"role": "user", "content": "What are the latest AI models released?"}
3]
4
5# First turn with search
6response = client.chat.completions.create(
7    model="selam-turbo",
8    messages=messages,
9    tools=[{"type": "web_search"}]
10)
11
12# Add assistant response to conversation
13messages.append({
14    "role": "assistant",
15    "content": response.choices[0].message.content
16})
17
18# Follow-up question (search context is maintained)
19messages.append({
20    "role": "user",
21    "content": "Which one would you recommend for coding tasks?"
22})
23
24response = client.chat.completions.create(
25    model="selam-turbo",
26    messages=messages
27)

Response Format

Responses with web search include citations to sources when appropriate:

1{
2  "id": "chatcmpl-xxx",
3  "object": "chat.completion",
4  "created": 1234567890,
5  "model": "selam-turbo",
6  "choices": [{
7    "index": 0,
8    "message": {
9      "role": "assistant",
10      "content": "Based on recent web search results, the latest AI developments include...\n\nSources:\n- https://example.com/article1\n- https://example.com/article2"
11    },
12    "finish_reason": "stop"
13  }],
14  "usage": {
15    "prompt_tokens": 150,
16    "completion_tokens": 200,
17    "total_tokens": 350
18  }
19}

Rate Limits

Web search respects your API tier rate limits. There are no additional rate limits specifically for the search feature.

System Capacity

  • 20+ million searches per day across all users
  • Load balanced across multiple endpoints
  • Automatic failover for high reliability

Error Handling

If web search fails for any reason, your request will continue without search results. The system handles failures gracefully:

1# Even if search fails, you'll still get a response
2try:
3    response = client.chat.completions.create(
4        model="selam-turbo",
5        messages=[{"role": "user", "content": "What is AI?"}],
6        tools=[{"type": "web_search"}]
7    )
8    # Response generated, possibly without web search context
9    print(response.choices[0].message.content)
10except Exception as e:
11    print(f"Request failed: {e}")

Warning

Search failures are logged but don't block your request. The model will respond based on its training data if search is unavailable.

Best Practices

1# For general queries with search
2model="selam-turbo"
3tools=[{"type": "web_search"}]
4
5# For search-optimized queries
6model="selam-search"  # No tools needed

2. Formulate Clear Queries

✓ Good: Specific, clear queries

1"What are the latest developments in quantum computing from 2024?"

✗ Less optimal: Vague queries

1"Tell me about stuff"

3. Use Search When Needed

Only enable web search when you need current information:

  • Current events and news
  • Recent developments in a field
  • Real-time data (prices, weather, etc.)
  • Latest research or publications

4. Handle Citations

The model will naturally cite sources from search results. You can parse these citations for display:

1response_text = response.choices[0].message.content
2
3# The response will include citations like:
4# "According to recent reports [1], quantum computing has advanced...
5# Sources:
6# [1] https://example.com/quantum-news"
7
8# You can parse and display these citations in your UI

Troubleshooting

Search Not Working

  • Verify you're not using a built-in search model (like selam-search)
  • Ensure you include tools=[{type: "web_search"}] in your request
  • Check your API key has the necessary permissions

Slow Responses

  • Very broad queries may take longer to search
  • Try more specific queries for faster results
  • Consider using streaming for better perceived performance

No Search Results

  • Query may be too specific - try broader terms
  • Search may have failed gracefully - check response for citations
  • Model will still respond based on training data

Example Use Cases

📰 News and Current Events

Get the latest news and developments in any field

1"What are the major tech announcements from this week?"

💰 Real-time Data

Access current prices, statistics, and metrics

1"What is the current price of Bitcoin?"

🔬 Research and Publications

Find recent research papers and academic publications

1"What are the latest breakthroughs in cancer research?"

🏆 Events and Awards

Get information about recent events and achievements

1"Who won the latest Nobel Prize in Physics?"

Related Resources

Was this page helpful?