Generative APIs - Quickstart
Scaleway Generative APIs provide programmatic access to AI models for generating new content, such as text and code.
By using our pre-configured, serverless endpoints of leading AI models, you eliminate the need to configure hardware or deploy your own models.
Hosted in European data centers and priced competitively per million tokens used, Generative 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
Interacting with Generative APIs via the playground
The Scaleway console provides a web playground for chat-based models hosted on Generative APIs. This allows you to interact with these models via a visual interface, sending your prompt and getting an immediate text-based response.
How to access the playground
-
Navigate to Generative APIs under the AI section of the Scaleway console side menu. The list of available models displays.
-
Click the name of the chat model you want to try. Alternatively, click more icon next to the chat model, and click Try model in the menu.
The web playground displays.
How to use the playground
-
Choose a model from the drop-down list at the top of the page.
-
Enter a prompt at the bottom of the page, for example
Tell me a joke. -
Edit the hyperparameters listed on the right column, for example the default temperature for more or less randomness on the model's output.
-
Click the send button to send your prompt and view the model's response in the conversation area, for example
Why don’t scientists trust atoms anymore? Because they make up everything!
Interacting with Generative APIs programatically
This example shows you how to start using Generative APIs in your Python code, via the OpenAI Python SDK.
How to install the OpenAI Python SDK
Run the following command:
pip install openaiHow to configure and set your API key and service URL
-
Have your Scaleway API key ready, or generate a new one from the Scaleway console.
-
Add the following code to your Python script:
from openai import OpenAI client = OpenAI( base_url="https://api.scaleway.ai/v1", # # Scaleway's Generative APIs service URL api_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.
How to send your first API request
After installing OpenAI and adding setting up the client with the base URL and API key, you are now ready to make your first API request.
Below is an example for generating a description of a futuristic city.
-
Ensure your code already contains the openai import statement and creation of a configured OpenAI client as shown above.
-
Create a chat completion for Llama 3.1 8b instruct by adding the following to your code:
completion = 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 result by adding the following to your code:
print(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.