Getting started overview
Newton provides an interactive, web-based environment for mathematical computations and data visualization. For developers, the Newton API extends this functionality, allowing programmatic interaction with its computational engine and notebook features. This guide outlines the process of setting up a Newton account, obtaining necessary credentials, and executing a foundational API request.
The core steps involve creating a Newton account, subscribing to a plan that includes API access (if the free tier is insufficient for your needs), generating an API key, and then using this key to authenticate a request to the Newton API. For interactive use, the web interface is the primary mechanism, while the API facilitates automation, embedding, and integration with other systems.
This reference focuses on the technical steps required to initiate API interaction. A general understanding of RESTful API principles and JSON data formats is assumed for programmatic examples.
Quick start reference
The following table provides a high-level overview of the getting started process:
| Step | What to Do | Where to Do It |
|---|---|---|
| 1. Create Account | Register for a Newton account. | Newton homepage signup |
| 2. Choose Plan (Optional) | Select a paid plan if API access beyond free tier limits is needed. | Newton pricing page |
| 3. Generate API Key | Locate and generate your API key within your account settings. | Newton Dashboard > Settings > API Keys |
| 4. Install HTTP Client | Set up a tool or library to make HTTP requests (e.g., cURL, Postman, Python requests). | Your local development environment |
| 5. Make First Request | Construct and send an authenticated request to a Newton API endpoint. | Your chosen HTTP client |
Create an account and get keys
Account creation
To begin with Newton, navigate to the Newton homepage and initiate the signup process. This typically involves providing an email address, setting a password, or using a third-party authentication provider (e.g., Google or GitHub). Upon successful registration, you will gain access to your Newton dashboard.
Choosing a plan
Newton offers an Explorer free tier that provides access to core features and limited storage. For advanced usage, higher rate limits, or specific API capabilities, you may need to upgrade to a paid plan. Information on plan features and pricing can be found on the Newton pricing page. Ensure your chosen plan includes the necessary API access permissions and rate limits for your intended use case.
Generating API keys
API keys are essential for authenticating your programmatic requests to the Newton API. To generate your key:
- Log in to your Newton account.
- Navigate to your dashboard.
- Locate the 'Settings' or 'Developer' section.
- Find the 'API Keys' subsection.
- Generate a new API key. It is common practice for keys to be displayed only once upon generation; copy it immediately and store it securely.
Treat your API key as sensitive information, similar to a password. Do not embed it directly in client-side code, commit it to public version control systems, or expose it in publicly accessible logs. For server-side applications, use environment variables or a secrets management service to store API keys securely. The OAuth 2.0 framework, for instance, provides mechanisms for secure API access without direct key exposure in many client-side scenarios, as detailed in the OAuth 2.0 specification.
Your first request
Once you have obtained your API key, you can make your first authenticated request. For this example, we will use curl, a common command-line tool for making HTTP requests. Replace YOUR_API_KEY with the key you generated.
Newton's API typically involves sending mathematical expressions or computational tasks in a JSON payload and receiving results. A common entry point might be an endpoint to evaluate a simple expression.
Example API call: Evaluate expression
Let's assume a hypothetical /evaluate endpoint that accepts a JSON body with an expression field.
curl -X POST \
https://api.newton.so/v1/evaluate \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{ "expression": "2 + 2 * (3 - 1)" }'
Upon successful execution, the API should return a JSON response similar to this:
{
"status": "success",
"result": "6",
"expression_evaluated": "2 + 2 * (3 - 1)"
}
This example demonstrates a basic authenticated request: a POST request with a JSON body and an Authorization header containing your API key prefixed with Bearer. The Content-Type: application/json header indicates that the request body is in JSON format.
Using a programming language
For more complex interactions, you would typically use an HTTP client library in your preferred programming language. Here is an example using Python's requests library:
import requests
import os
api_key = os.environ.get("NEWTON_API_KEY") # Securely retrieve API key
base_url = "https://api.newton.so/v1"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}"
}
data = {
"expression": "sin(pi/2) + cos(0)"
}
try:
response = requests.post(f"{base_url}/evaluate", headers=headers, json=data)
response.raise_for_status() # Raise an HTTPError for bad responses (4xx or 5xx)
print(response.json())
except requests.exceptions.HTTPError as err:
print(f"HTTP error occurred: {err}")
except requests.exceptions.RequestException as err:
print(f"An error occurred: {err}")
Remember to install the requests library (pip install requests) and set the NEWTON_API_KEY environment variable before running this code. Secure handling of API keys via environment variables is a common practice, as advised by security best practices for Google API client libraries, among others.
Common next steps
After successfully making your first API call, consider these common next steps to further integrate with Newton:
- Explore API Documentation: Thoroughly review the official Newton API documentation for a complete list of available endpoints, request parameters, and response structures. This will detail capabilities such as notebook creation, data manipulation, and advanced computational functions.
- Implement Error Handling: Integrate robust error handling into your application to gracefully manage API rate limits, authentication failures, and other potential issues. Newton's API responses typically include error codes and messages that can be used for debugging.
- Manage Authentication Securely: For production environments, implement more sophisticated API key management, potentially using a secrets manager or environment variables to avoid hardcoding credentials.
- Integrate with Notebooks: If your use case involves managing interactive notebooks, explore endpoints related to creating, updating, and executing code within Newton notebooks programmatically.
- Monitor Usage: Utilize any available dashboard features or API endpoints to monitor your API usage, especially if you are on a tiered plan with usage limits.
- Explore SDKs: Check if Newton provides official Software Development Kits (SDKs) for your preferred programming language. SDKs can simplify API interactions by abstracting HTTP requests and providing language-specific constructs.
Troubleshooting the first call
If your initial API call encounters issues, consider the following common troubleshooting steps:
- Check API Key: Ensure your API key is correct and has not been truncated or altered. Verify it matches the key generated in your Newton account settings.
- Verify Authorization Header: Confirm the
Authorizationheader is correctly formatted asBearer YOUR_API_KEY. Missing the 'Bearer' prefix or incorrect spacing can lead to authentication failures. - Inspect Content-Type Header: For
POSTorPUTrequests with a JSON body, ensure theContent-Type: application/jsonheader is present and correctly spelled. - Review Endpoint URL: Double-check that the API endpoint URL is accurate (e.g.,
https://api.newton.so/v1/evaluate) and matches the documentation. - Examine Request Body: If sending a JSON payload, ensure it is valid JSON and adheres to the structure expected by the specific endpoint. Use a JSON linter to validate.
- Check HTTP Status Codes: The HTTP status code in the response provides immediate feedback:
401 Unauthorized: Often indicates an invalid or missing API key.403 Forbidden: May mean your API key lacks the necessary permissions for the requested action, or your plan does not support that feature.400 Bad Request: Typically points to an issue with the request body or parameters.404 Not Found: The requested endpoint does not exist.5xx Server Error: Indicates an issue on Newton's side; report these to Newton support.- Consult Newton Documentation: Refer to the official Newton API error documentation for detailed explanations of specific error codes and messages returned by the API.
- Network Connectivity: Ensure your development environment has stable internet connectivity and no firewalls or proxies are blocking access to
api.newton.so.
By systematically checking these points, you can typically identify and resolve issues preventing a successful first API call.