-
Notifications
You must be signed in to change notification settings - Fork 394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add page about Studio REST API #4681
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
5260c54
add page about REST API
aguschin c031684
link to adding credentials to studio
aguschin d10fb04
make link relative
aguschin 9d7f82b
fix api handler name
aguschin 0c7c289
add page about studio python api
aguschin 7d1fb17
fix format of request description
aguschin 832efae
Merge branch 'main' into studio/api
aguschin ba1fe76
note about latest version
aguschin 5059499
Merge branch 'studio/api' of github.com:iterative/dvc.org into studio…
aguschin 3e22bfc
explain monorepo case
aguschin 4c971c6
add link to apis
aguschin d777c0a
Update content/docs/studio/rest-api.md
aguschin 2f46406
link from dvc api; add with to download_model
aguschin ef0c38c
Merge branch 'studio/api' of github.com:iterative/dvc.org into studio…
aguschin 0855839
drop studio python api
7134202
Merge branch 'main' into studio/api
a4f66a2
minor edits to studio api
b291eee
add stage
f68bf78
studio api: add expiration time
d0139df
Merge branch 'main' into studio/api
a6493f4
studio api: add python example
87f9402
Merge branch 'main' into studio/api
bb54bda
use model registry abbr
e2aa45a
Merge branch 'main' into studio/api
b87e2f7
reference studio rest api in artifacts get and reframe around model r…
166599d
reference studio rest api in api.artifacts_show
ef27fc3
reword artifacts get fallback
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -755,7 +755,8 @@ | |
] | ||
} | ||
] | ||
} | ||
}, | ||
"rest-api" | ||
] | ||
}, | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# REST API | ||
|
||
The purpose of Studio REST API is to give programmatic access to information in | ||
Studio and executing actions in it. | ||
|
||
The API is hosted under the `/api` route on the Studio server: | ||
https://studio.iterative.ai/api or https://your-domain/api in case of | ||
[self-hosted Studio](/doc/studio/self-hosting/installation). | ||
|
||
To use API, you need to generate | ||
[Studio access token](/doc/studio/user-guide/account-management#studio-access-token). | ||
|
||
## Download model | ||
|
||
Get signed URL to download the model binaries for a model from the <abbr>model | ||
registry</abbr>. Requires the model to be stored with DVC with S3 or Azure | ||
[remote]. Note, that you need to | ||
[set up remote cloud credentials](/doc/studio/user-guide/account-management#cloud-credentials) | ||
for Studio to have rights to the signed URLs. The signed URLs expire after one | ||
hour. | ||
|
||
```yaml | ||
Endpoint: api/model-registry/get-download-uris | ||
HTTP Method: GET | ||
``` | ||
|
||
### Request | ||
|
||
| param | desc | type | required | example value | | ||
| ------- | ------------- | ------ | -------- | ---------------------------------- | | ||
| repo | Git repo URL | string | true | iterative/demo-bank-customer-churn | | ||
| name | Model name | string | true | randomforest-model | | ||
| version | Model version | string | false | v2.0.0 | | ||
dberenbaum marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| stage | Model stage | string | false | prod | | ||
|
||
Only one of stage or version is allowed. If no version or stage is specified, | ||
the latest version is returned. | ||
|
||
When your model is annotated in non-root [`dvc.yaml`] file (typical for monorepo | ||
case), model name will be constructed from two parts separated by colon: | ||
`path/to/dvc/yaml:model_name`. For example, take a look at this | ||
[model from example-get-started-experiments repo](https://studio.iterative.ai/user/aguschin/models/VtQdva13kMSPsN_N8004aQ==/pool-segmentation/v1.0.1). | ||
Its full name that you need to use in API is `results/train:pool-segmentation`. | ||
|
||
| header | desc | example value | | ||
| ------------- | --------------- | ------------- | | ||
| Authorization | Header for auth | token abc123 | | ||
|
||
### Response | ||
|
||
Response is a JSON-encoded dict. If the request was successful, keys will be | ||
paths to files inside the repo, and values will be signed URLs you can query to | ||
actually download the model. | ||
|
||
### Example | ||
|
||
First, you need your [Studio access token]. For this example, we set it in the | ||
`DVC_STUDIO_TOKEN` environment variable: | ||
|
||
```sh | ||
export DVC_STUDIO_TOKEN=<TOKEN> | ||
``` | ||
|
||
<toggle> | ||
|
||
<tab title="Python"> | ||
|
||
```python | ||
import json | ||
import os | ||
import requests | ||
|
||
|
||
url = "https://studio.iterative.ai/api/model-registry/get-download-uris" | ||
token = os.environ["DVC_STUDIO_TOKEN"] | ||
headers = {"Authorization": f"token {token}"} | ||
params = { | ||
"repo": "[email protected]:iterative/demo-bank-customer-churn.git", | ||
"name": "randomforest-model", | ||
"version": "v2.0.0" | ||
} | ||
|
||
response = requests.get(url, headers=headers, params=params) | ||
for rel_path, obj_url in json.loads(response.content).items(): | ||
obj = requests.get(obj_url) | ||
... | ||
``` | ||
|
||
</tab> | ||
|
||
<tab title="CLI"> | ||
|
||
```sh | ||
$ curl "https://studio.iterative.ai/api/model-registry/[email protected]:iterative/demo-bank-customer-churn.git&name=randomforest-model&version=v2.0.0" --header "Authorization:token ${DVC_STUDIO_TOKEN}" | ||
|
||
{ | ||
dberenbaum marked this conversation as resolved.
Show resolved
Hide resolved
|
||
".mlem/model/clf-model": "https://sandbox-datasets-iterative.s3.amazonaws.com/bank-customer-churn/86/bd02376ac675568ba2fac566169ef9?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAU7UXIWDIQFPCO76Q%2F20230706%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20230706T134619Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&X-Amz-Signature=6807259ddd1f4448ed1e3c5d4503039884f7779381ee556175096b0a884ba1a6" | ||
} | ||
``` | ||
|
||
</tab> | ||
|
||
<admon type="warn"> | ||
|
||
Running this example will fail because it requires that you have [set up remote | ||
cloud credentials] in Studio to where the model is stored. | ||
|
||
</admon> | ||
|
||
[remote]: /doc/user-guide/data-management/remote-storage | ||
[`dvc.yaml`]: /doc/user-guide/project-structure/dvcyaml-files | ||
[Studio access token]: | ||
/doc/studio/user-guide/account-management#studio-access-token | ||
[set up remote cloud credentials]: | ||
/doc/studio/user-guide/account-management#cloud-credentials |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this also support a Studio project ID per https://github.com/iterative/studio/pull/6338#issuecomment-1596468450? My feeling is it still might be useful since users have to do a lookup either way and this requires less escaping than a full repo url.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not rn. But we can add it in some future. Adding this as an item to "out of scope of phase I" https://github.com/iterative/studio/issues/5177