Anthropic-Compatible RAG

Drop-in replacement for the Anthropic Messages API — with your YourGPT knowledgebase built in.

Endpoint: POST https://api.yourgpt.ai/chatbot/v1/anthropic/v1/messages

Set base_url to https://api.yourgpt.ai/chatbot/v1/anthropic in the Anthropic SDK — it appends /v1/messages automatically. Add a yourgpt:knowledgebase server tool and the endpoint handles retrieval automatically.

import anthropic

client = anthropic.Anthropic(
    api_key="apk-your-api-key",
    base_url="https://api.yourgpt.ai/chatbot/v1/anthropic",
)

response = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    system="You are a helpful support agent.",
    messages=[{"role": "user", "content": "What is your refund policy?"}],
    tools=[
        {"type": "yourgpt:knowledgebase", "parameters": {"limit": 5}}
    ],
)

print(response.content[0].text)

Authentication

Pass your apk-... project API key as the Anthropic api_key. The SDK sends it in x-api-key, which YourGPT accepts automatically.

Request limits

LimitValue
User message length5,000 characters
Tool round-trips per request5

model, max_tokens, and messages are all required. At least one user message must contain text.

Newer Claude models do not support temperature, top_p, or top_k.

Server tools

Add these to the tools array alongside any of your own Anthropic tool definitions. Your own tools are passed through to the model unchanged — see User-defined tools.

yourgpt:knowledgebase

Injects a search_knowledgebase tool into Claude. Claude calls it when it decides retrieval is needed.

{
  "type": "yourgpt:knowledgebase",
  "parameters": {
    "limit": 5,
    "mode": "tool_only"
  }
}
ParameterTypeDefaultDescription
limitinteger5Chunks to retrieve per call. Range: 1–20.
modestring"tool_only""tool_only" — Claude calls the tool on-demand. "hybrid" — YourGPT retrieves relevant context before the Claude call, and keeps the tool available for follow-ups.

tool_only — best when the conversation mixes KB and non-KB questions. Claude only searches when it decides to.

hybrid — best for always-on KB answers (support bots, FAQ). Context is retrieved up front so Claude can answer immediately. Costs slightly more per request.

Injects a web_search tool. Claude calls it for live information outside your knowledgebase. Each result includes title, URL, and up to 3,000 chars of text.

{
  "type": "yourgpt:web_search",
  "parameters": {
    "max_results": 5
  }
}
ParameterTypeDefaultDescription
max_resultsinteger5Web results per call. Range: 1–25.

User-defined tools

Any tool in tools[] without a yourgpt:* type is your own tool. YourGPT forwards it to Claude unchanged and, when Claude calls it, hands the call back to you exactly as the Anthropic API would — stop_reason: "tool_use" with a tool_use content block. Execute it and POST back a tool_result block to continue the conversation.

Knowledgebase and web search run server-side and never appear as tool_use blocks in your response.

If Claude calls one of your tools and a server tool in the same turn, the server tool's result is dropped for that turn — Claude may request it again on the next turn.

Response

Standard Anthropic response shape plus a sources array.

{
  "content": [{ "type": "text", "text": "..." }],
  "stop_reason": "end_turn",
  "usage": { "input_tokens": 312, "output_tokens": 48 },
  "sources": [
    {
      "type": "knowledgebase",
      "content": "You can reset your password from...",
      "score": 0.921,
      "doc_id": "doc_abc123"
    },
    {
      "type": "web",
      "title": "EU Consumer Rights",
      "url": "https://example.com/eu-consumer-rights",
      "text": "Consumers in the EU have..."
    }
  ]
}

Every entry is tagged with type — knowledgebase chunks and web results share one array.

typeFields
knowledgebasecontent, score, doc_id
webtitle, url, text

sources is empty when nothing was retrieved, and is de-duplicated — the same document or URL appears at most once.

sources is a YourGPT addition to the standard Anthropic response. Typed SDK clients won't expose it as an attribute — read it from the raw response (e.g. response.model_dump()["sources"] in Python, or the parsed JSON body in other languages).

Streaming

Set "stream": true — response is standard Anthropic SSE format. sources is attached to the message_delta event.

Examples

Rate limits & errors

PlanRequests/hr
Professional200
Advanced / Agency1000
Statuserror.typeMeaning
400invalid_request_errorMissing model, max_tokens, or messages, no user text, message over 5,000 chars, non claude-* model, or yourgpt:web_search unavailable
400invalid_request_errorModel not available on your plan, or no active subscription
401authentication_errorInvalid or missing API key
402insufficient_creditsOrganization has no remaining credits
429rate_limit_errorHourly limit exceeded
500api_errorInternal error, or Claude made 5 tool round-trips without finishing

Errors returned by Anthropic itself are forwarded with their original status and message.

On this page