> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://docs.instabase.com/api-sdk/api-reference/secrets/create-secret/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.instabase.com/_mcp/server. # Create secret POST https://aihub.instabase.com/api/v2/aihub/secrets Content-Type: application/json Create a new secret in this organization.Only organization admins can create secrets. Reference: https://docs.instabase.com/api-sdk/api-reference/secrets/create-secret ## Authentication - `Authorization` header (bearer token, required) — Bearer HTTP authentication. ## Request ### Headers - `IB-Context` (string, optional) — Typically your organization ID. See [Authorization and context identification](/api-sdk/authorization#ib-context-header) for details. ### Body (application/json) This endpoint expects an object. - `alias` (string, required) — Name of the secret. - `value` (string, required) — Content of the secret. - `allowed_workspaces_type` (enum, required) — Which workspaces in this organization are allowed to use this secret in custom functions. - Allowed values: `ALL`, `SOME`, `NONE` - `description` (string, optional) — Description of the secret. - `allowed_workspaces` (list of string, optional) — Which workspaces are allowed to use this secret, if only some are allowed. Required when `allowed_workspaces_type` is `SOME`, otherwise ignored. ## Response ### 200 Secret created successfully. ## Examples **Request** ```json { "alias": "db_admin_password", "value": "S3cureP@ssw0rd!", "allowed_workspaces_type": "ALL" } ``` **Response** ```json {} ``` **SDK Code** ```python with SDK from aihub import AIHub client = AIHub( api_root="https://aihub.instabase.com/api", api_key="abcdefghijklmnopqrst1234567890", ib_context="john.doe_acme.com" ) # returns None client.secrets.create( alias="my_secret", description="Sample secret", value="my password", allowed_workspaces_type="SOME", allowed_workspaces=["workspace1", "workspace2"] ) ``` ```python without SDK import requests url = "https://aihub.instabase.com/api/v2/aihub/secrets" headers = { "Authorization": "Bearer abcdefghijklmnopqrst1234567890", "IB-Context": "john.doe_acme.com" } # create the request payload data = { "alias": "my_secret", "description": "Sample secret", "value": "my password", "allowed_workspaces_type": "SOME", "allowed_workspaces": ["workspace1", "workspace2"] } # make the POST request response = requests.post(url, headers=headers, json=data) # handle the response if response.status_code == 200: print("Secret created successfully") else: print(f"Error: {response.status_code} - {response.text}") ``` ```javascript const url = 'https://aihub.instabase.com/api/v2/aihub/secrets'; const options = { method: 'POST', headers: {Authorization: 'Bearer ', 'Content-Type': 'application/json'}, body: '{"alias":"db_admin_password","value":"S3cureP@ssw0rd!","allowed_workspaces_type":"ALL"}' }; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://aihub.instabase.com/api/v2/aihub/secrets" payload := strings.NewReader("{\n \"alias\": \"db_admin_password\",\n \"value\": \"S3cureP@ssw0rd!\",\n \"allowed_workspaces_type\": \"ALL\"\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer ") 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 require 'uri' require 'net/http' url = URI("https://aihub.instabase.com/api/v2/aihub/secrets") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Authorization"] = 'Bearer ' request["Content-Type"] = 'application/json' request.body = "{\n \"alias\": \"db_admin_password\",\n \"value\": \"S3cureP@ssw0rd!\",\n \"allowed_workspaces_type\": \"ALL\"\n}" response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://aihub.instabase.com/api/v2/aihub/secrets") .header("Authorization", "Bearer ") .header("Content-Type", "application/json") .body("{\n \"alias\": \"db_admin_password\",\n \"value\": \"S3cureP@ssw0rd!\",\n \"allowed_workspaces_type\": \"ALL\"\n}") .asString(); ``` ```php request('POST', 'https://aihub.instabase.com/api/v2/aihub/secrets', [ 'body' => '{ "alias": "db_admin_password", "value": "S3cureP@ssw0rd!", "allowed_workspaces_type": "ALL" }', 'headers' => [ 'Authorization' => 'Bearer ', 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp using RestSharp; var client = new RestClient("https://aihub.instabase.com/api/v2/aihub/secrets"); var request = new RestRequest(Method.POST); request.AddHeader("Authorization", "Bearer "); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"alias\": \"db_admin_password\",\n \"value\": \"S3cureP@ssw0rd!\",\n \"allowed_workspaces_type\": \"ALL\"\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = [ "Authorization": "Bearer ", "Content-Type": "application/json" ] let parameters = [ "alias": "db_admin_password", "value": "S3cureP@ssw0rd!", "allowed_workspaces_type": "ALL" ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://aihub.instabase.com/api/v2/aihub/secrets")! 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() ```