Developer quickstart
With the AI Hub API, you can integrate AI Hub functionality into your own workflows and tooling. The AI Hub API is a RESTful API that can be used with any language. AI Hub also offers a Python software development kit (SDK) and Postman collection to help interface with the API. The API documentation also features an API playground, letting you build and send requests within the reference documentation.
Account setup
To get started using the AI Hub API:
-
You must have an AI Hub account. See Getting started to learn how to create a community account or join or start an organization.
-
You must have an API token. After creating an account, you can generate an API token yourself.
-
You need your user ID or organization ID, to use in the
IB-Context
header. Read the context identification documentation to understand how theIB-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 theIB-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 header is undefined, the default behavior is to use your community account. This means if the header is undefined, your community account is the cost center for any requests that require consumption units to complete.
Using the Python SDK
The AI Hub SDK is published to the Python Package Index (PyPI). To install the AI Hub SDK, run the following command:
Initializing the 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, run the following command:
Fill in the api_root
, api_key
, and ib_context
values as follows:
With the SDK installed and client initialized, you can follow any Python SDK example provided in the AI Hub API reference. SDK examples are marked with # AI Hub Python SDK example
.
Using Postman
An AI Hub API collection is available in Postman, an API platform for building and using APIs. The AI Hub collection includes automation so that responses from one API call are automatically populated in subsequent 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.
After making a copy of the collection, you can set up your authorization and context identification variables on the Variables tab.
Update the Current value column for the following commonly used variables, then click Save.
Using curl
curl is a common but minimalist command line tool that can be used to make HTTP requests. While you can interact with the AI Hub API in any language, all endpoint references include a curl example.
All curl examples reference the API root, API token, and IB-Context
header values as variables. For example:
If you don’t set up these variables, define them as follows:
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:
-
Edit the root API URL used in the request URL, to support custom AI Hub domains. Double-click to edit the field.
-
Add your API token, letting you send real requests using your AI Hub account.
-
Customize your request, adding and defining supported headers and parameters. The request URL updates when you define path or query parameters.
-
Select from cURL, TypeScript, and Python for the generated request language.
-
Send the request and see the response.
-
Copy the request you’ve built.
To open the API playground view, open any endpoint in the API reference section, then click the Play button found above the request sample.
Testing
To test your setup, you can 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.
A successful response returns a 201
status code and a JSON object containing a batch ID, such as {"id":231}
.
Python SDK
Run the following command:
Postman
Navigate to the Batches > Create batch endpoint and click Run.
curl
Run the following command:
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.
What's next
With your setup complete and tested, you can start interacting with the AI Hub API. Your next steps might include:
-
Running an AI Hub app using the AI Hub SDK.
-
Creating a Converse conversation using the AI Hub SDK.
-
Learning about all AI Hub API endpoints with the AI Hub API reference. For supported endpoints, a Python SDK example is provided.
-
Learning about tracking billing and usage, as well as how unit consumption is calculated for AI Hub operations that use consumption units.
-
Review AI Hub release notes, where API and SDK changes are noted.