This service is free while in beta. Specific terms and conditions apply.
Generative APIs - Quickstart
Generative APIs offer seamless access to pre-configured, serverless endpoints of leading AI models. No need to configure hardware or deploy your own models.
Hosted in European data centers and priced competitively per million tokens used, these APIs enable efficient and scalable integration of AI capabilities into your applications.
Before you start
To complete the actions presented below, you must have:
- A Scaleway account logged into the console
- Owner status or IAM permissions allowing you to perform actions in the intended Organization
- A valid API key
- Python 3.7+ installed on your system
Start with the Generative APIs Playground
Scaleway provides a web playground for instruct-based models hosted on Generative APIs.
Accessing the Playground
- Navigate to Generative APIs under the AI section of the Scaleway console side menu. The list of models you can query displays.
- Click the name of the chat model you want to try. Alternatively, click «See more Icon» next to the chat model, and click Try model in the menu.
The web playground displays.
Using the playground
- Enter a prompt at the bottom of the page, or use one of the suggested prompts in the conversation area.
- Edit the hyperparameters listed on the right column, for example the default temperature for more or less randomness on the outputs.
- Switch models at the top of the page, to observe the capabilities of chat models offered via Generative APIs.
- Click View code to get code snippets configured according to your settings in the playground.
Install the OpenAI Python SDK
To start using Generative APIs in your code, you can install the OpenAI Python SDK. Run the following command:
pip install openai
Ensure Python is installed on your local machine. If you need to install Python, download it from python.org.
Configure and set your API key and service URL
- Have your API key ready or generate a new one from the Scaleway console.
- Use the following code in your Python script:
from openai import OpenAIclient = OpenAI(base_url="https://api.scaleway.ai/v1", # # Scaleway's Generative APIs service URLapi_key="<SCW_SECRET_KEY>" # Your unique API secret key from Scaleway)
Make sure that you replace <SCW_SECRET_KEY>
with the API key obtained from your Scaleway account.
It is recommended to store your API keys securely using environment variables or secret management tools to prevent unauthorized access.
Send your first API request
You are now ready to make your first API request. Below is an example of generating a description of a futuristic city:
from openai import OpenAI# Initialize the client with your base URL and API keyclient = OpenAI(base_url="https://api.scaleway.ai/v1",api_key="<SCW_API_KEY>")# Create a chat completion for Llama 3.1 8b instructcompletion = client.chat.completions.create(model="llama-3.1-8b-instruct",messages=[{"role": "user", "content": "Describe a futuristic city with advanced technology and green energy solutions."}],temperature=0.7,max_tokens=100)# Output the resultprint(completion.choices[0].message.content)
This very simple example demonstrates how the Chat API can be used to generate creative content based on your prompts.
Going further
Now that you are familiar with the basics, explore the full potential of Generative APIs by customizing your API requests. Refer to our How-to guides for more advanced features and usage.