---
title: Calculate capital gains taxes
slug: calculate-capital-gains-taxes
docTags: 
createdAt: 2023-11-11T16:06:16.033Z
---

{
  "id": "KqcvO48Q5aZEagzNlycr7",
  "type": "api-oas-v2",
  "data": {
    "method": "POST",
    "url": "https://osifinance.com/api/v1/federal-capital-gains-taxes",
    "servers": [
      {
        "url": "https://osifinance.com/api/v1/federal-capital-gains-taxes"
      }
    ],
    "name": "Calculate capital gains taxes",
    "contentType": "application/json",
    "request": {
      "pathParameters": [],
      "headerParameters": [],
      "queryParameters": [],
      "bodyDataParameters": [
        {
          "kind": "required",
          "name": "body",
          "type": "object",
          "description": "Parameters for calculating capital gains taxes",
          "schema": [
            {
              "name": "api_key",
              "kind": "required",
              "type": "string",
              "description": "API key needed to authorize requests",
              "modelRef": "#/components/schemas/ApiKey",
              "customType": "ApiKey",
              "schema": []
            },
            {
              "name": "sources",
              "kind": "optional",
              "type": "boolean",
              "description": "Whether to include sources for the specific endpoint",
              "default": false,
              "modelRef": "#/components/schemas/Sources",
              "customType": "Sources",
              "schema": []
            },
            {
              "name": "filing_status",
              "kind": "optional",
              "type": "string",
              "description": "Filing status for taxes.",
              "default": "single",
              "modelRef": "#/components/schemas/FilingStatus",
              "customType": "FilingStatus",
              "schema": []
            },
            {
              "name": "federal_agi",
              "kind": "optional",
              "type": "integer",
              "description": "Federal adjusted gross income (agi).",
              "default": 75000,
              "modelRef": "#/components/schemas/FederalAgi",
              "customType": "FederalAgi",
              "schema": []
            },
            {
              "name": "capital_gains_long",
              "kind": "optional",
              "type": "integer",
              "description": "Long term capital gains.",
              "default": 0,
              "modelRef": "#/components/schemas/CapitalGainsLong",
              "customType": "CapitalGainsLong",
              "schema": []
            },
            {
              "name": "capital_gains_short",
              "kind": "optional",
              "type": "integer",
              "description": "Short term capital gains.",
              "default": 0,
              "modelRef": "#/components/schemas/CapitalGainsShort",
              "customType": "CapitalGainsShort",
              "schema": []
            },
            {
              "name": "dependents",
              "kind": "optional",
              "type": "integer",
              "description": "Number of dependents.",
              "default": 0,
              "modelRef": "#/components/schemas/Dependents",
              "customType": "Dependents",
              "schema": []
            },
            {
              "name": "birth_year",
              "kind": "optional",
              "type": "integer",
              "description": "Year of birth.",
              "default": 1990,
              "modelRef": "#/components/schemas/BirthYear",
              "customType": "BirthYear",
              "schema": []
            },
            {
              "name": "filersOver65",
              "kind": "optional",
              "type": "integer",
              "description": "Number of filers over 65.",
              "default": 0,
              "modelRef": "#/components/schemas/FilersOver65",
              "customType": "FilersOver65",
              "schema": []
            },
            {
              "name": "traditional_esp_contributions",
              "kind": "optional",
              "type": "integer",
              "description": "Traditional employer sponsored plan contributions (401(k), 429(b), 457(b)).",
              "default": 0,
              "modelRef": "#/components/schemas/TraditionalEspContributions",
              "customType": "TraditionalEspContributions",
              "schema": []
            },
            {
              "name": "traditional_ira_contributions",
              "kind": "optional",
              "type": "integer",
              "description": "Traditional IRA contributions.",
              "default": 0,
              "modelRef": "#/components/schemas/TraditionalIraContributions",
              "customType": "TraditionalIraContributions",
              "schema": []
            },
            {
              "name": "pmi",
              "kind": "optional",
              "type": "integer",
              "description": "Monthly Social Security benefits.",
              "default": 0,
              "modelRef": "#/components/schemas/Pmi",
              "customType": "Pmi",
              "schema": []
            }
          ],
          "isExpanded": true
        }
      ],
      "formDataParameters": [],
      "oAuthParameters": []
    },
    "responses": [
      {
        "statusCode": "200",
        "description": "OK",
        "jsonExample": "",
        "isExpanded": true,
        "schema": [
          {
            "kind": "optional",
            "type": "object",
            "schema": [
              {
                "name": "status",
                "kind": "optional",
                "type": "string<success>",
                "description": "Success message",
                "example": ""
              },
              {
                "name": "data",
                "kind": "optional",
                "type": "object",
                "example": "",
                "schema": [
                  {
                    "name": "Tax Type",
                    "kind": "optional",
                    "type": "object",
                    "description": "List of tax types",
                    "example": "",
                    "schema": []
                  },
                  {
                    "name": "Marginal Tax Rate",
                    "kind": "optional",
                    "type": "object",
                    "description": "Marginal tax rate for each tax type",
                    "example": "",
                    "schema": []
                  },
                  {
                    "name": "Effective Tax Rate",
                    "kind": "optional",
                    "type": "object",
                    "description": "Effective tax rate for each tax type",
                    "example": "",
                    "schema": []
                  },
                  {
                    "name": "2023 Taxes",
                    "kind": "optional",
                    "type": "object",
                    "description": "2023 taxes for each tax type",
                    "example": "",
                    "schema": []
                  }
                ]
              },
              {
                "name": "sources",
                "kind": "optional",
                "type": "object",
                "description": "List of sources",
                "example": "",
                "schema": []
              }
            ],
            "isExpanded": true
          }
        ]
      },
      {
        "statusCode": "400",
        "description": "Bad request",
        "jsonExample": "",
        "isExpanded": true,
        "schema": [
          {
            "kind": "optional",
            "type": "object",
            "schema": [
              {
                "name": "error",
                "kind": "optional",
                "type": "string",
                "description": "Error message",
                "example": ""
              }
            ],
            "isExpanded": true
          }
        ]
      },
      {
        "statusCode": "401",
        "description": "Unauthorized",
        "jsonExample": "",
        "isExpanded": true,
        "schema": [
          {
            "kind": "optional",
            "type": "object",
            "schema": [
              {
                "name": "error",
                "kind": "optional",
                "type": "string<No API key provided. Please provide an API Key. | Invalid API key provided. Please register at https://osifinance.com/signup to get a valid API key.>",
                "description": "Error message",
                "example": ""
              }
            ],
            "isExpanded": true
          }
        ]
      },
      {
        "statusCode": "404",
        "description": "Not found",
        "jsonExample": "",
        "isExpanded": true,
        "schema": [
          {
            "kind": "optional",
            "type": "object",
            "schema": [
              {
                "name": "error",
                "kind": "optional",
                "type": "string",
                "description": "Error message",
                "example": ""
              }
            ],
            "isExpanded": true
          }
        ]
      },
      {
        "statusCode": "429",
        "description": "Too Many Requests",
        "jsonExample": "",
        "isExpanded": true,
        "schema": [
          {
            "kind": "optional",
            "type": "object",
            "schema": [
              {
                "name": "error",
                "kind": "optional",
                "type": "string<Usage Limit Reached. You have reached the maximum number of daily requests for your account. You can get a higher limit by upgrading to a paid plan or through our give2get program. Learn more at https://osifinance.com/resources/help/give2get?question=How%20can%20I%20get%20free,%20unlimited%20access%20to%20the%20API%20and%20calculators?.>",
                "description": "Error message",
                "example": ""
              }
            ],
            "isExpanded": true
          }
        ]
      },
      {
        "statusCode": "500",
        "description": "Internal server error",
        "jsonExample": "",
        "isExpanded": true,
        "schema": [
          {
            "kind": "optional",
            "type": "object",
            "schema": [
              {
                "name": "error",
                "kind": "optional",
                "type": "string",
                "description": "Error message",
                "example": ""
              }
            ],
            "isExpanded": true
          }
        ]
      }
    ],
    "examples": {
      "languages": [
        {
          "id": "30bZJqDRo2FyS6_CHop5v",
          "language": "curl",
          "label": "cURL",
          "code": "curl --request POST \\\n     --url https://osifinance.com/api/v1/federal-capital-gains-taxes \\\n     --header 'accept: application/json' \\\n     --header 'content-type: application/json' \\\n     --data '{\n     \"api_key\": \"\",\n     \"filing_status\": \"single\",\n     \"federal_agi\": 75000,\n     \"birth_year\": 1990\n     }'"
        },
        {
          "id": "RTMnKoK_w6d6DJ51eMQZi",
          "language": "javascript",
          "label": "javascript",
          "code": "var myHeaders = new Headers();\nmyHeaders.append(\"accept\", \"application/json\");\nmyHeaders.append(\"content-type\", \"application/json\");\n\nvar raw = JSON.stringify({\n   \"api_key\": \"\",\n   \"filing_status\": \"single\",\n   \"federal_agi\": 75000,\n   \"birth_year\": 1990\n});\n\nvar requestOptions = {\n   method: 'POST',\n   headers: myHeaders,\n   body: raw,\n   redirect: 'follow'\n};\n\nfetch(\"https://osifinance.com/api/v1/federal-capital-gains-taxes\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));"
        },
        {
          "id": "bSSWVDrzIGAePZ_G7WdyV",
          "language": "ruby",
          "label": "Ruby",
          "code": "require \"uri\"\nrequire \"json\"\nrequire \"net/http\"\n\nurl = URI(\"https://osifinance.com/api/v1/federal-capital-gains-taxes\")\n\nhttps = Net::HTTP.new(url.host, url.port)\nhttps.use_ssl = true\n\nrequest = Net::HTTP::Post.new(url)\nrequest[\"accept\"] = \"application/json\"\nrequest[\"content-type\"] = \"application/json\"\nrequest.body = JSON.dump({\n   \"api_key\": \"\",\n   \"filing_status\": \"single\",\n   \"federal_agi\": 75000,\n   \"birth_year\": 1990\n})\n\nresponse = https.request(request)\nputs response.read_body\n"
        },
        {
          "id": "le0Osw6JrYQAJM5soHcSb",
          "language": "python",
          "label": "Python",
          "code": "import requests\nimport json\n\nurl = \"https://osifinance.com/api/v1/federal-capital-gains-taxes\"\n\npayload = json.dumps({\n   \"api_key\": \"\",\n   \"filing_status\": \"single\",\n   \"federal_agi\": 75000,\n   \"birth_year\": 1990\n})\nheaders = {\n   'accept': 'application/json',\n   'content-type': 'application/json'\n}\n\nresponse = requests.request(\"POST\", url, headers=headers, data=payload)\n\nprint(response.text)\n"
        }
      ],
      "selectedLanguageId": "30bZJqDRo2FyS6_CHop5v"
    },
    "results": {
      "languages": [
        {
          "id": "c6iJBuKpDrzRnFmoY-4Hy",
          "language": "200",
          "code": "// OK\n{\n  \"status\": \"\",\n  \"data\": {\n    \"Tax Type\": {},\n    \"Marginal Tax Rate\": {},\n    \"Effective Tax Rate\": {},\n    \"2023 Taxes\": {}\n  },\n  \"sources\": {}\n}"
        },
        {
          "id": "ZYe3LaMDNqCHR9XEkbEg7",
          "language": "400",
          "code": "// Bad request\n{\n  \"error\": \"\"\n}"
        },
        {
          "id": "DyCy2FlPs_hoJ72PqTxBv",
          "language": "401",
          "code": "// Unauthorized\n{\n  \"error\": \"\"\n}"
        },
        {
          "id": "RUFSKifNOvZi6FmC2chPF",
          "language": "404",
          "code": "// Not found\n{\n  \"error\": \"\"\n}"
        },
        {
          "id": "zQF33eWpsgZLg0INn0M-3",
          "language": "429",
          "code": "// Too Many Requests\n{\n  \"error\": \"\"\n}"
        },
        {
          "id": "ZqV0DL2l6E1rCjHR-2pqz",
          "language": "500",
          "code": "// Internal server error\n{\n  \"error\": \"\"\n}"
        }
      ],
      "selectedLanguageId": "c6iJBuKpDrzRnFmoY-4Hy"
    }
  },
  "children": [
    {
      "text": ""
    }
  ]
}