Skip to main contentwatsonx Developer Hub

Quick start

Make your first API request to watsonx.ai

Get started with your first API or SDK requests with watsonx.ai to generate responses from a prompt.

1. Visit Developer Access page

To begin using the API and SDK, you will need 3 values: a project or space id, an endpoint for your region, and an API key. You can visit the Developer Access page to receive these values. Make sure to also follow the link on the Developer Access page to get your IBM Cloud API key separately.

2. Start Building

3. Create a token

You authenticate to watsonx.ai by including a bearer token in your requests. The token is generated from an API key that you own.

Create an IAM Bearer token by making a request to the IAM Identity Services API with your API key. Replace {apikey} with the value of the API key that you created.

1curl -X POST \
2-H "Content-Type: application/x-www-form-urlencoded" \
3https://iam.cloud.ibm.com/identity/token \
4-d "grant_type=urn:ibm:params:oauth:grant-type:apikey&apikey={apikey}"

4. Make your API request to infer text

Run the following curl request to infer text from text input. Replace {token}, {watsonx_ai_url}, and {project_id} with information from your account.

1curl -X POST \
2-H "Authorization: Bearer {token}" \
3-H "Content-Type: application/json" \
4"{watsonx_ai_url}/ml/v1/text/generation?version=2024-05-31" \
5--data-raw '{
6   "input": "How far is Paris from Bangalore?",
7   "model_id": "ibm/granite-13b-instruct-v2",
8   "project_id": "{project_id}"
9}'

Next steps

Now that you successfully made a simple request with watsonx.ai, learn about other features and capabilities.

  • Try your request against another foundation model by changing the model_id from ibm/granite-13b-instruct-v2 to another ID. For information about how to find the model IDs, see Models.

  • Experiment with Text generation, Chat or Tool calling