Developer quickstart

With the AI Hub API, you can integrate AI Hub functionality into your own workflows and tooling.

You can interact with the AI Hub API in several ways:

  • Use the AI Hub software development kit (SDK), which wraps API calls in Python classes and methods. The SDK is the easiest way to get started.

  • Call RESTful API endpoints with curl or any programming language.

  • Use the AI Hub Postman collection to make API calls.

  • Use the playground feature in the API reference documentation. This can help you learn the API by sending requests directly from the documentation pages.

Account setup

Before using the AI Hub API, you must complete several prerequisites.

  • You must have an AI Hub account. See Getting started to learn how to create a community account or join or start an organization.

    To make API or SDK calls that aren’t tied to a particular user, use a service account.
  • You must have an API token. After creating an account, you can generate an API token.

  • You must have your user ID or organization ID to use in the IB-Context header. Read the context identification documentation to understand how the IB-Context header is used, its default behavior, and where to find your user ID and organization ID.

    If you belong to an organization, passing your organization ID in the IB-Context header is the only way to identify a request as coming from your organization account. Your API token is tied to both your community account and your organization account.
    If the IB-Context header is undefined, AI Hub will use consumption units from your community account.

Using the AI Hub SDK

The AI Hub SDK requires Python 3.7 or higher. No other languages are supported.

The SDK is published to the Python Package Index (PyPI). To install the SDK, run the following command:

$pip install instabase-aihub
If you’re new to installing Python packages, see the Python Packaging User Guide tutorial for installing packages. The tutorial covers getting started topics such as installation requirements and creating a virtual environment.

Initializing the SDK with an API client

When using the AI Hub SDK, you must initialize the API client with your own api_key, api_root, and ib_context values. The client can then handle authorization and context identification when interacting with the AI Hub API through the SDK.

To initialize the API client, start a Python script with this code:

1from aihub import AIHub
2
3client = AIHub(api_root=<API-ROOT>,
4 api_key=<API-TOKEN>,
5 ib_context=<IB-CONTEXT>)
ParameterTypeValue
api_rootstrYour AI Hub root URL.
Community accounts: omit setting api_root.
Organization accounts: If your organization has a custom AI Hub domain, use your organization’s root API URL, such as https://my-org.instabase.com/api. If not, omit setting api_root.
api_keystrYour API token.
ib_contextstrThe value for the IB-Context header that the SDK includes with all API requests.
Community accounts: omit setting ib_context.
Commercial accounts:
- To use your personal account, set to your user ID.
- To use your organization account, set to your organization ID.

With the SDK installed and the client initialized, you can use any SDK sample code provided in the API and SDK documentation pages.

Selecting Python from the API code sample language dropdown
Viewing SDK sample code from an API documentation page

Using curl

curl is a command line tool for making HTTP requests, including calls to API endpoints The playground feature in the reference documentation for each API endpoint includes examples that use curl.

Here’s an example of using curl to call the batches endpoint:

$ curl "${API_ROOT}/v2/batches" \
> -H "Authorization: Bearer ${API_TOKEN}" \
> -H "IB-Context: ${IB_CONTEXT}"\
> -H "Content-Type: application/json" \
> -d '{"name": "test"}'

All curl calls use the environment variables API-ROOT, API-TOKEN, and IB-Context.

VariableValue
${API_ROOT}Your AI Hub root URL.
- Community accounts: use https://aihub.instabase.com/api.
- Organization accounts: if your organization has a custom AI Hub domain, enter your organization’s root API URL, such as https://my-organization.instabase.com/api. If not, use the default AI Hub root API URL.
${API_TOKEN}Your API token.
${IB_CONTEXT}The value to use for the IB-Context header.
- To use your community account, enter your user ID or omit the IB-Context header.
- To use your organization account, use your organization ID.

You’re not limited to curl. You can access API endpoints with any language that makes HTTP requests. For example, the API reference documentation’s playground feature shows Python and Typescript code for making direct API calls to each endpoint.

Using Postman

An AI Hub API collection is available in Postman, a platform for building and using APIs. The AI Hub collection includes automation, so responses from one API call are automatically populated in later calls.

To get started, click Run in Postman and fork or import the collection. If given the option, enable notifications for any changes to the collection.

button to run postman

After making a copy of the collection, you can set up your authorization and context identification variables. In Postman, click Instabase AI Hub in the left navigation panel and click the Variables tab.

The Variables tab of a Postman collection, viewed in Postman's desktop app

Update the Current value column for the following commonly used variables, then click Save.

VariableValue
API_ROOTYour AI Hub root URL.
Community accounts: accept the default.
Organization accounts: if your organization has a custom AI Hub domain, enter your organization’s root API URL, such as https://my-organization.instabase.com/api. Accept the default if not.
API_KEYYour API token.
USER_IDYour user ID.
ORGANIZATION_IDYour organization ID.
Community accounts: accept the default.
Organization accounts: enter your organization ID.
CONTEXTThe value for the IB-Context header.
- To use your community account, enter {{USER_ID}}
- To use your organization account, enter {{ORGANIZATION_ID}}

Using the API playground

The AI Hub API reference documentation includes an API playground feature, an interactive tool that lets you build and send requests. You can:

  1. Edit the root API URL used in the request URL, to support custom AI Hub domains. Double-click to edit the field.

  2. Add your API token, letting you send real requests using your AI Hub account.

  3. Customize your request, adding and defining supported headers and parameters. The request URL updates when you define path or query parameters.

  4. Select from curl, TypeScript, and Python for the generated request language.

  5. Send the request and see the response.

  6. Copy the request you’ve built.

API playground view, highlighting action locations

To open the API playground view, open any endpoint in the API reference section, then click Play above the request sample.

API playground Play button, within a request sample

Testing

To test your setup, make a basic request that requires no consumption units to complete, such as calling the Create batch endpoint. This endpoint creates an empty resource called a batch. If there are no errors, your setup works.

SDK

Run the following command:

1from aihub import AIHub
2
3# initialize the SDK client
4client = AIHub(api_key=<API-TOKEN>,
5 api_root=<API-ROOT>,
6 ib_context=<IB-CONTEXT>)
7
8batch = client.batches.create(name='test-batch')

curl

Run the following command:

$curl "${API_ROOT}/v2/batches" \
> -H "Authorization: Bearer ${API_TOKEN}" \
> -H "IB-Context: ${IB_CONTEXT}"\
> -H "Content-Type: application/json" \
> -d '{"name": "test-batch"}'

Postman

Navigate to the Batches > Create batch endpoint and click Run.

API playground

Navigate to the create batch endpoint reference. In the request sample frame, click Play to open the API playground view, enter test in the name parameter, then click Send Request.

A successful response returns a 201 status code and a JSON object containing a batch ID, such as {"id": 231}.

Next steps

With your setup complete and tested, you’re ready to interact with the AI Hub API. Your next steps might include:

Was this page helpful?