For clean Markdown of any page, append .md to the page URL. For a complete documentation index, see https://docs.synthflow.ai/api-reference/platform-api/knowledge-bases/llms.txt. For full documentation content, see https://docs.synthflow.ai/api-reference/platform-api/knowledge-bases/llms-full.txt.

# Add a knowledge base source

POST https://api.synthflow.ai/v2/knowledge_base/{knowledge_base_id}/sources
Content-Type: application/json

Reference: https://docs.synthflow.ai/api-reference/platform-api/knowledge-bases/attach-document-to-source

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: Synthflow APIs
  version: 1.0.0
paths:
  /knowledge_base/{knowledge_base_id}/sources:
    post:
      operationId: attach-document-to-source
      summary: Add a knowledge base source
      tags:
        - ''
      parameters:
        - name: knowledge_base_id
          in: path
          required: true
          schema:
            $ref: '#/components/schemas/knowledge_base_id'
        - name: Authorization
          in: header
          description: Bearer authentication
          required: true
          schema:
            type: string
      responses:
        '200':
          description: '200'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/attachDocumentToSource_Response_200'
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  description: Source name.
                type:
                  $ref: >-
                    #/components/schemas/KnowledgeBaseKnowledgeBaseIdSourcesPostRequestBodyContentApplicationJsonSchemaType
                  description: Source type.
                url:
                  type: string
                  description: >-
                    Source URL. Required when type is `pdf` (URL to a hosted PDF
                    file) or `web` (URL to a website to scrape)
                content:
                  type: string
                  description: >-
                    The full text content for the knowledge base source.
                    Required when type is `text`
servers:
  - url: https://api.synthflow.ai/v2
  - url: https://api.us.synthflow.ai/v2
components:
  schemas:
    knowledge_base_id:
      type: string
      description: Knowledge base ID.
      title: knowledge_base_id
    KnowledgeBaseKnowledgeBaseIdSourcesPostRequestBodyContentApplicationJsonSchemaType:
      type: string
      enum:
        - pdf
        - text
        - web
      description: Source type.
      title: >-
        KnowledgeBaseKnowledgeBaseIdSourcesPostRequestBodyContentApplicationJsonSchemaType
    KnowledgeBaseKnowledgeBaseIdSourcesPostResponsesContentApplicationJsonSchemaResponse:
      type: object
      properties:
        body:
          type: string
        knowledge_base_id:
          $ref: '#/components/schemas/knowledge_base_id'
        knowledge_base_source_id:
          type: string
      title: >-
        KnowledgeBaseKnowledgeBaseIdSourcesPostResponsesContentApplicationJsonSchemaResponse
    attachDocumentToSource_Response_200:
      type: object
      properties:
        status:
          type: string
        response:
          $ref: >-
            #/components/schemas/KnowledgeBaseKnowledgeBaseIdSourcesPostResponsesContentApplicationJsonSchemaResponse
      title: attachDocumentToSource_Response_200
  securitySchemes:
    sec0:
      type: http
      scheme: bearer

```

## SDK Code Examples

```python Add PDF Source
import requests

url = "https://api.synthflow.ai/v2/knowledge_base/1739253053024x397207388602947460/sources"

payload = {
    "name": "Product Documentation",
    "type": "pdf",
    "url": "https://example.com/documents/product-guide.pdf"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```go Add PDF Source
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.synthflow.ai/v2/knowledge_base/1739253053024x397207388602947460/sources"

	payload := strings.NewReader("{\n  \"name\": \"Product Documentation\",\n  \"type\": \"pdf\",\n  \"url\": \"https://example.com/documents/product-guide.pdf\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Add PDF Source
require 'uri'
require 'net/http'

url = URI("https://api.synthflow.ai/v2/knowledge_base/1739253053024x397207388602947460/sources")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"name\": \"Product Documentation\",\n  \"type\": \"pdf\",\n  \"url\": \"https://example.com/documents/product-guide.pdf\"\n}"

response = http.request(request)
puts response.read_body
```

```java Add PDF Source
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.synthflow.ai/v2/knowledge_base/1739253053024x397207388602947460/sources")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"name\": \"Product Documentation\",\n  \"type\": \"pdf\",\n  \"url\": \"https://example.com/documents/product-guide.pdf\"\n}")
  .asString();
```

```csharp Add PDF Source
using RestSharp;

var client = new RestClient("https://api.synthflow.ai/v2/knowledge_base/1739253053024x397207388602947460/sources");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"name\": \"Product Documentation\",\n  \"type\": \"pdf\",\n  \"url\": \"https://example.com/documents/product-guide.pdf\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Add PDF Source
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "name": "Product Documentation",
  "type": "pdf",
  "url": "https://example.com/documents/product-guide.pdf"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.synthflow.ai/v2/knowledge_base/1739253053024x397207388602947460/sources")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

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()
```

```python Add Text Source
import requests

url = "https://api.synthflow.ai/v2/knowledge_base/1739253053024x397207388602947460/sources"

payload = {
    "name": "Custom Knowledge",
    "type": "text",
    "content": "This is the full text content that will be added directly to the knowledge base."
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```go Add Text Source
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.synthflow.ai/v2/knowledge_base/1739253053024x397207388602947460/sources"

	payload := strings.NewReader("{\n  \"name\": \"Custom Knowledge\",\n  \"type\": \"text\",\n  \"content\": \"This is the full text content that will be added directly to the knowledge base.\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Add Text Source
require 'uri'
require 'net/http'

url = URI("https://api.synthflow.ai/v2/knowledge_base/1739253053024x397207388602947460/sources")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"name\": \"Custom Knowledge\",\n  \"type\": \"text\",\n  \"content\": \"This is the full text content that will be added directly to the knowledge base.\"\n}"

response = http.request(request)
puts response.read_body
```

```java Add Text Source
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.synthflow.ai/v2/knowledge_base/1739253053024x397207388602947460/sources")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"name\": \"Custom Knowledge\",\n  \"type\": \"text\",\n  \"content\": \"This is the full text content that will be added directly to the knowledge base.\"\n}")
  .asString();
```

```csharp Add Text Source
using RestSharp;

var client = new RestClient("https://api.synthflow.ai/v2/knowledge_base/1739253053024x397207388602947460/sources");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"name\": \"Custom Knowledge\",\n  \"type\": \"text\",\n  \"content\": \"This is the full text content that will be added directly to the knowledge base.\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Add Text Source
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "name": "Custom Knowledge",
  "type": "text",
  "content": "This is the full text content that will be added directly to the knowledge base."
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.synthflow.ai/v2/knowledge_base/1739253053024x397207388602947460/sources")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

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()
```

```python Add Web Source
import requests

url = "https://api.synthflow.ai/v2/knowledge_base/1739253053024x397207388602947460/sources"

payload = {
    "name": "Company FAQ",
    "type": "web",
    "url": "https://example.com/faq"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```go Add Web Source
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.synthflow.ai/v2/knowledge_base/1739253053024x397207388602947460/sources"

	payload := strings.NewReader("{\n  \"name\": \"Company FAQ\",\n  \"type\": \"web\",\n  \"url\": \"https://example.com/faq\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Add Web Source
require 'uri'
require 'net/http'

url = URI("https://api.synthflow.ai/v2/knowledge_base/1739253053024x397207388602947460/sources")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"name\": \"Company FAQ\",\n  \"type\": \"web\",\n  \"url\": \"https://example.com/faq\"\n}"

response = http.request(request)
puts response.read_body
```

```java Add Web Source
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.synthflow.ai/v2/knowledge_base/1739253053024x397207388602947460/sources")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"name\": \"Company FAQ\",\n  \"type\": \"web\",\n  \"url\": \"https://example.com/faq\"\n}")
  .asString();
```

```csharp Add Web Source
using RestSharp;

var client = new RestClient("https://api.synthflow.ai/v2/knowledge_base/1739253053024x397207388602947460/sources");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"name\": \"Company FAQ\",\n  \"type\": \"web\",\n  \"url\": \"https://example.com/faq\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Add Web Source
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "name": "Company FAQ",
  "type": "web",
  "url": "https://example.com/faq"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.synthflow.ai/v2/knowledge_base/1739253053024x397207388602947460/sources")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

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()
```